anketa = $anketa; $this->spremenljivka = $sprID; SurveyAnalysis::Init($this->anketa); SurveyAnalysis::$setUpJSAnaliza = false; SurveyChart::Init($this->anketa); // create new PPT document $this->ppt = new PHPPowerPoint(); // Poskrbimo za datoteko s podatki $SDF = SurveyDataFile::get_instance(); $SDF->init($this->anketa); $SDF->prepareFiles(); $this->headFileName = $SDF->getHeaderFileName(); $this->dataFileName = $SDF->getDataFileName(); $this->dataFileStatus = $SDF->getStatus(); SurveyZankaProfiles :: Init($this->anketa, $global_user_id); $this->current_loop = ($loop != null) ? $loop : $this->current_loop; // preberemo nastavitve iz baze (prej v sessionu) SurveyUserSession::Init($this->anketa); $this->sessionData = SurveyUserSession::getData('charts'); } else{ return false; } if ( SurveyInfo::getInstance()->SurveyInit($this->anketa) ){ SurveyUserSetting::getInstance()->Init($this->anketa, $global_user_id); $this->skin = SurveyUserSetting :: getInstance()->getSettings('default_chart_profile_skin'); $this->numbering = SurveyDataSettingProfiles :: getSetting('chartNumbering'); $this->frontpage = SurveyDataSettingProfiles :: getSetting('chartFP'); } else return false; return true; } function getFile($fileName) { //Close and output PDF document ob_end_clean(); $objWriter = PHPPowerPoint_IOFactory::createWriter($this->ppt, 'PowerPoint2007'); header("Pragma: no-cache"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=".$fileName); ob_clean(); flush(); $objWriter->save('php://output'); //readfile(str_replace('.php', '.pptx', __FILE__)); exit; } function encodeText($text) { // popravimo sumnike ce je potrebno $text = html_entity_decode($text, ENT_NOQUOTES, 'UTF-8'); $text = str_replace(array("š","š","č"),array("�","�","�"),$text); return strip_tags($text); } function createPpt(){ global $site_path; global $lang; $this->ppt->getProperties()->setCreator("1ka"); $this->ppt->getProperties()->setLastModifiedBy("1ka"); $this->ppt->getProperties()->setTitle("PPT Izvoz"); $this->ppt->getProperties()->setSubject("PPT Izvoz"); $this->ppt->getProperties()->setDescription("PPT Izvoz grafov"); $this->ppt->getProperties()->setKeywords("office 2007 openxml php"); $this->ppt->getProperties()->setCategory("PPT Izvoz grafov"); $this->ppt->removeSlideByIndex(0); // izpisemo prvo stran if($this->frontpage == 1){ $this->createFrontPage(); } # preberemo header if ($this->headFileName !== null) { //polovimo podatke o nastavitvah trenutnega profila (missingi..) SurveyAnalysis::$missingProfileData = SurveyMissingProfiles::getProfile(SurveyAnalysis::$currentMissingProfile); // Preverimo ce imamo zanke (po skupinah) SurveyAnalysis::$_LOOPS = SurveyZankaProfiles::getFiltersForLoops(); # če nimamo zank if(count(SurveyAnalysis::$_LOOPS) == 0){ $this->displayCharts(); } else{ // izrisemo samo eno tabelo iz enega loopa if($this->current_loop > 0){ $loop = SurveyAnalysis::$_LOOPS[(int)$this->current_loop-1]; $loop['cnt'] = $this->current_loop; SurveyAnalysis::$_CURRENT_LOOP = $loop; $this->displayCharts(); } // Izrisemo vse tabele spremenljivka (iz vseh loopov) else{ $loop_cnt = 0; # če mamo zanke foreach(SurveyAnalysis::$_LOOPS AS $loop) { $loop_cnt++; $loop['cnt'] = $loop_cnt; SurveyAnalysis::$_CURRENT_LOOP = $loop; // Izpisemo naslov zanke za skupino /*$currentSlide = $this->ppt->createSlide(); $shape = $currentSlide->createRichTextShape(); $shape->setHeight(30); $shape->setWidth(600); $shape->setOffsetX(20); $shape->setOffsetY(90); //$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $textRun = $shape->createTextRun($lang['srv_zanka_note'].$loop['text']); $textRun->getFont()->setBold(true); $textRun->getFont()->setSize(12); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) );*/ $this->displayCharts(); } } } } // end if else ($_headFileName == null) } function displayCharts(){ global $site_path; global $lang; #preberemo HEADERS iz datoteke SurveyAnalysis::$_HEADERS = unserialize(file_get_contents($this->headFileName)); # polovimo frekvence SurveyAnalysis::getFrequencys(); $vars_count = count(SurveyAnalysis::$_FILTRED_VARIABLES); #odstranimo sistemske variable SurveyAnalysis::removeSystemVariables(); foreach (SurveyAnalysis::$_HEADERS AS $spid => $spremenljivka) { # preverjamo ali je meta if (($spremenljivka['tip'] != 'm' && in_array($spremenljivka['tip'], SurveyAnalysis::$_FILTRED_TYPES )) && (!isset($_spid) || (isset($_spid) && $_spid == $spid)) && ($this->spremenljivka == $spid || $this->spremenljivka == null) ) { # ali imamo sfiltrirano spremenljivko if ($vars_count == 0 || ($vars_count > 0 && isset(SurveyAnalysis::$_FILTRED_VARIABLES[$spid]) ) ) { // Ce imamo radio tip in manj kot 5 variabel po defaultu prikazemo piechart $vars = count($spremenljivka['options']); $type = 0; if( ($spremenljivka['tip'] == 1 || $spremenljivka['tip'] == 3) && $vars < 5 ) $type = 2; //ce imamo nominalno spremenljivko ali ce je samo 1 variabla nimamo povprecij if($spremenljivka['tip'] == 6 && ($spremenljivka['cnt_all'] == 1 || $spremenljivka['skala'] == 1) && $type == 0 ) $type = 2; /*if($spremenljivka['tip'] == 4 || $spremenljivka['tip'] == 19 || $spremenljivka['tip'] == 21 || $spremenljivka['tip'] == 22){ // ce imamo vklopljeno nastavitev prikaz tabel med grafi (default) if($spremenljivka['tip'] == 19) self::sumMultiText($spid, 'sums'); else self::frequencyVertical($spid); }*/ if( in_array($spremenljivka['tip'],array(1,2,3,6,7,8,16,17,18,20)) ){ // Prikazemo posamezen graf $this->displayChart($spid, $type); } } } // end if $spremenljivka['tip'] != 'm' } // end foreach self::$_HEADERS } // Vstavimo graf function displayChart($spid, $type=0, $sort=0, $value_type=0){ global $site_path; global $lang; $spremenljivka = SurveyAnalysis::$_HEADERS[$spid]; // ce ga imamo v sessionu ga preberemo if(isset($this->sessionData[$spid])){ // Napolnimo podatke za graf - rabimo za cache if(count(SurveyAnalysis::$_LOOPS) == 0) $settings =$this->sessionData[$spid]; else $settings = $this->sessionData[$spid][SurveyAnalysis::$_CURRENT_LOOP['cnt']]; $DataSet = SurveyChart::getDataSet($spid, $settings); // nimamo nobenih podatkov in imamo vklopljeno opcijo da ne prikazujemo praznih grafov - vrnemo 0 if($DataSet == 0){ self::displayEmptyWarning($spid); return; } // preberemo ime slike iz sessiona $imgName = $settings['name']; } // ce ga nimamo v sessionu else{ // Napolnimo podatke za graf - rabimo za cache $settings = SurveyChart::getDefaultSettings(); $DataSet = SurveyChart::getDataSet($spid, $settings); // nimamo nobenih podatkov in imamo vklopljeno opcijo da ne prikazujemo praznih grafov - vrnemo 0 if($DataSet == 0){ self::displayEmptyWarning($spid); return; } $ID = self::generateChartId($spid, $settings, $DataSet->GetNumerus()); $Cache = new pCache('pChart/Cache/'); $Cache = new pCache('../survey/pChart/Cache/'); $imgName = $Cache->GetHash($ID,$DataSet->GetData()); } $stevilcenje = ($this->numbering == 1 ? $spremenljivka['variable'].' - ' : ''); $title = $stevilcenje . $spremenljivka['naslov']; if(SurveyDataSettingProfiles :: getSetting('chartNumerusText') == 0){ $title .= ' (n = '.$DataSet->GetNumerus().')'; } // IZRIS GRAFA $currentSlide = $this->ppt->createSlide(); // slika $shape = $currentSlide->createDrawingShape(); $shape->setName('Chart'); $shape->setDescription($title); $shape->setPath('../survey/pChart/Cache/'.$imgName); $shape->setWidth(800); //$shape->setHeight(400); $shape->setOffsetX(75); $shape->setOffsetY(130); // naslov $shape = $currentSlide->createRichTextShape(); $shape->setHeight(80); $shape->setWidth(600); $shape->setOffsetX(170); $shape->setOffsetY(40); $shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $textRun = $shape->createTextRun($title); $textRun->getFont()->setBold(true); $textRun->getFont()->setSize(16); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) ); if($spremenljivka['tip'] == 2){ $shape = $currentSlide->createRichTextShape(); $shape->setHeight(30); $shape->setWidth(600); $shape->setOffsetX(170); $shape->setOffsetY(90); $shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $textRun = $shape->createTextRun($lang['srv_info_checkbox']); $textRun->getFont()->setBold(false); $textRun->getFont()->setSize(12); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) ); } # izpišemo še tekstovne odgovore za polja drugo /*$_answersOther = $DataSet->GetOther(); if (count($_answersOther) > 0 && SurveyAnalysis::$_FILTRED_OTHER) { foreach ($_answersOther AS $oAnswers) { self::outputOtherAnswers($oAnswers); } }*/ } // dodamo prvo stran function createFrontPage(){ global $lang; $currentSlide = $this->ppt->createSlide(); $shape = $currentSlide->createRichTextShape(); $shape->setWidth(600); $shape->setOffsetX(170); $shape->setOffsetY(200); $shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $textRun = $shape->createTextRun(SurveyInfo::getInstance()->getSurveyTitle()); $textRun->getFont()->setBold(true); $textRun->getFont()->setSize(38); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) ); $shape->createBreak(); $textRun = $shape->createTextRun($lang['srv_analiza_charts']); $textRun->getFont()->setBold(true); $textRun->getFont()->setSize(22); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) ); $shape->createBreak(); $shape->createBreak(); $textRun = $shape->createTextRun($this->getEntryDates()); $textRun->getFont()->setBold(false); $textRun->getFont()->setSize(14); $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) ); } function setUserId($usrId) {$this->anketa['uid'] = $usrId;} function getUserId() {return ($this->anketa['uid'])?$this->anketa['uid']:false;} // vrnemo string za prvi in zadnji vnos function getEntryDates(){ global $lang; $prvi_vnos_date = SurveyInfo::getSurveyFirstEntryDate(); $prvi_vnos_time = SurveyInfo::getSurveyFirstEntryTime(); $zadnji_vnos_date = SurveyInfo::getSurveyLastEntryDate(); $zadnji_vnos_time = SurveyInfo::getSurveyLastEntryTime(); if ($prvi_vnos_date != null) { $first = $this->dateFormat($prvi_vnos_date,'j.n.y'); $first .= $prvi_vnos_time != null ? (SurveyInfo::$dateTimeSeperator .$this->dateFormat($prvi_vnos_time,'G:i')) : ''; } if ($zadnji_vnos_date != null) { $last = $this->dateFormat($zadnji_vnos_date,'j.n.y'); $last .= $zadnji_vnos_time != null ? (SurveyInfo::$dateTimeSeperator .$this->dateFormat($zadnji_vnos_time,'G:i')) : ''; } $text = $lang['srv_setting_collectdata_datetime'].$first.' '.$lang['s_to'].' '.$last; return $text; } function dateFormat($input, $format) { if ($input != '..') { return date($format,strtotime($input)); } else { return ''; } } function formatNumber($value,$digit=0,$sufix="") { if ( $value <> 0 && $value != null ) $result = round($value,$digit); else $result = "0"; $result = number_format($result, $digit, ',', '.').$sufix; return $result; } /** Izriše frekvence v vertikalni obliki * * @param unknown_type $spid */ function frequencyVertical($spid) { global $lang; $spremenljivka = SurveyAnalysis::$_HEADERS[$spid]; # če je besedilo * in je samo ena kategorija je inline legenda false $inline_legenda = (SurveyAnalysis::$_HEADERS[$spid]['cnt_all'] == 1 || in_array($spremenljivka['tip'],array(1,8) ) ) ? false: true; # koliko zapisov prikažemo naenkrat //$num_show_records = SurveyAnalysis::getNumRecords(); $chartTableMore = SurveyDataSettingProfiles :: getSetting('chartTableMore'); $num_show_records = ($chartTableMore == 0) ? 10 : 1000; // ce imamo prazno in ne prikazujemo praznih tabel $hideEmpty = SurveyDataSettingProfiles :: getSetting('hideEmpty'); if($hideEmpty == 1){ $emptyData = true; if (count($spremenljivka['grids']) > 0) foreach ($spremenljivka['grids'] AS $gid => $grid) { $_variables_count = count($grid['variables']); if ($_variables_count > 0 ) foreach ($grid['variables'] AS $vid => $variable ){ $_sequence = $variable['sequence']; # id kolone z podatki if(SurveyAnalysis::$_FREQUENCYS[$_sequence]['validCnt'] > 0) $emptyData = false; } } if($emptyData){ self::displayEmptyWarning($spid); return; } } $this->pdf->ln(5); $this->pdf->setFont('','b','6'); $stevilcenje = ($this->numbering == 1 ? $spremenljivka['variable'].' - ' : ''); $title = $stevilcenje . $spremenljivka['naslov']; $this->pdf->MultiCell(165, 5, $title, 0, 'C', 0, 1, 0 ,0, true); //prva vrstica /*$this->pdf->setFont('','b','6'); $this->pdf->MultiCell(18, 5, $this->encodeText($spremenljivka['variable']), 1, 'C', 0, 0, 0 ,0, true); $this->pdf->MultiCell(162, 5, $this->encodeText($spremenljivka['naslov']), 1, 'C', 0, 1, 0 ,0, true);*/ //druga vrstica self::tableHeader(); $this->pdf->setFont('','','6'); // konec naslovne vrstice $_answersOther = array(); # dodamo opcijo kje izrisujemo legendo $options=array('inline_legenda' => $inline_legenda, 'isTextAnswer' => false, 'isOtherAnswer' => false); # izpišemo vlejavne odgovore if (count($spremenljivka['grids']) > 0) foreach ($spremenljivka['grids'] AS $gid => $grid) { $_variables_count = count($grid['variables']); # dodamo dodatne vrstice z albelami grida if ($_variables_count > 0 ) foreach ($grid['variables'] AS $vid => $variable ){ $_sequence = $variable['sequence']; # id kolone z podatki if (($variable['text'] != true && $variable['other'] != true) || (in_array($spremenljivka['tip'],array(4,8,21)))){ # dodamo ime podvariable $counter = 0; $_kumulativa = 0; //SurveyAnalysis::$_FREQUENCYS[$_sequence] if (count(SurveyAnalysis::$_FREQUENCYS[$_sequence]['valid'])> 0 ) { foreach (SurveyAnalysis::$_FREQUENCYS[$_sequence]['valid'] AS $vkey => $vAnswer) { if ($counter < $num_show_records) { if ($vAnswer['cnt'] > 0 || true) { # izpisujemo samo tiste ki nisno 0 if (in_array($spremenljivka['tip'],array(4,7,8,19,20,21))) { // text, number, datum, mtext, mnumber, text* $options['isTextAnswer'] = true; # ali prikažemo vse odgovore ali pa samo toliko koliko je nastavljeno v TEXT_ANSWER_LIMIT $options['textAnswerExceed'] = ($counter >= TEXT_ANSWER_LIMIT && count(SurveyAnalysis::$_FREQUENCYS[$_sequence]['valid']) > TEXT_ANSWER_LIMIT+2) ? true : false; # ali začnemo skrivati tekstovne odgovore } else { $options['isTextAnswer'] = false; $options['textAnswerExceed'] = false; } $counter = self::outputValidAnswerVertical($counter,$vkey,$vAnswer,$_sequence,$spid,$_kumulativa,$options); } } } # izpišemo sumo veljavnih $counter = self::outputSumaValidAnswerVertical($counter,$_sequence,$spid,$options); } if (count(SurveyAnalysis::$_FREQUENCYS[$_sequence]['invalid'])> 0 ) { foreach (SurveyAnalysis::$_FREQUENCYS[$_sequence]['invalid'] AS $ikey => $iAnswer) { if ($iAnswer['cnt'] > 0 ) { # izpisujemo samo tiste ki nisno 0 $counter = self::outputInvalidAnswerVertical($counter,$ikey,$iAnswer,$_sequence,$spid,$options); } } # izpišemo sumo veljavnih $counter = self::outputSumaInvalidAnswerVertical($counter,$_sequence,$spid,$options); } #izpišemo še skupno sumo $counter = self::outputSumaVertical($counter,$_sequence,$spid,$options); } else { $_answersOther[] = array('spid'=>$spid,'gid'=>$gid,'vid'=>$vid,'sequence'=>$_sequence); } } } # izpišemo še tekstovne odgovore za polja drugo if (count($_answersOther) > 0 && SurveyAnalysis::$_FILTRED_OTHER) { foreach ($_answersOther AS $oAnswers) { //pdfIzvozAnalizaSums::outputOtherAnswers($oAnswers); } } $this->pdf->ln(5); } function outputValidAnswerVertical($counter,$vkey,$vAnswer,$_sequence,$spid,&$_kumulativa,$_options=array()) { global $lang; $text = array(); # opcije $options = array( 'isTextAnswer' => false, # ali je tekstovni odgovor 'isOtherAnswer' => false, # ali je odgovor Drugo 'inline_legenda' => true, # ali je legenda inline ali v headerju 'textAnswerExceed'=>false # ali presegamo število tekstovnih odgovorov za prikaz ); foreach ($_options as $_oKey => $_option) { $options[$_oKey] = $_option; } //$cssBck = ' '.SurveyAnalysis::$cssColors['0_' . ($counter & 1)]; $fill = ($counter % 2 == 1) ? 1 : 0; $_valid = (SurveyAnalysis::$_FREQUENCYS[$_sequence]['validCnt'] > 0 ) ? 100*$vAnswer['cnt'] / SurveyAnalysis::$_FREQUENCYS[$_sequence]['validCnt'] : 0; $_percent = (SurveyAnalysis::$_FREQUENCYS[$_sequence]['allCnt'] > 0 ) ? 100*$vAnswer['cnt'] / SurveyAnalysis::$_FREQUENCYS[$_sequence]['allCnt'] : 0; $_kumulativa += $_valid; # ali presegamo število prikazanih vrstic, takrat v zadnji prikazani dodamo link več.. ostale vrstice pa skrijemo if ($options['textAnswerExceed'] == true) { if ($counter == TEXT_ANSWER_LIMIT ) { # link za več $show_more = '