$answers = get_survey_answers($question->getId()); if (!empty($answers)) { ?> <form id="formQuestion<?php print_r($question->getId()); ?> " class="form ac" action="<?php echo ROOT_DIR . '?page=survey&funct=survey_submit'; ?> " method="POST"> <div class="ac"> <section class="clearfix prefix_2"> <?php foreach ($answers as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); $vote = new Vote(); $vote_id = 0; $user_vote_by_answer = array(); $user_vote_by_answer = get_user_vote_by_answer($user_id, $answer_id); if (!empty($user_vote_by_answer)) { $vote_id = $user_vote_by_answer[0]; $vote->get_from_db($vote_id); } ?> <label for = "formSurvey<?php print_r($question->getId()); ?> Answer<?php print_r($answer->getId()); ?>
function elementFunction() { // get global user object global $user; // set connection var global $db; // get current time $time_now = date("Y-m-d H:i:s"); // protect from unauthorized access if (!isset($user) or !isset($_POST['formElementFunction'])) { logout(); die; } // set empty survey $session_question = new Question(); $session_question = get_session_question(); $question_id = $_POST['formElementFunction']; if ($question_id != "") { $session_question->get_from_db($question_id); } // get the function $function = ''; foreach ($_POST as $key => $post) { if ($post != $question_id) { $function = substr($key, 11); } } if ($function == 'Edit') { // set security $survey = new Survey(); $survey->get_from_db($session_question->getSurvey()); if ($survey->getCreatedBy() != $user->getId()) { if ($user->getAdmin() != 1) { logout(); die; } } $_SESSION['session_question'] = serialize($session_question); // get session answers $session_answers = array(); $session_answer_ids = get_survey_answers($session_question->getId()); foreach ($session_answer_ids as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); array_push($session_answers, $answer); } $_SESSION['session_answers'] = serialize($session_answers); $cookie_key = 'msg'; $cookie_value = 'Вие избрахте елемент от анкетата за редакция!<br />Отидете на раздел "Добавете или редактирайте елемент към анкетата"'; setcookie($cookie_key, $cookie_value, time() + 1); header('Location: ' . ROOT_DIR . '?page=survey_edit'); die; } elseif ($function == 'PrintExcel') { // get global user object global $user; // get survey id $question_id = $_POST['formElementFunction']; // check if the user is the surveyCreator or systemAdmin $question = new Question(); $question->get_from_db($question_id); $survey = new Survey(); $survey->get_from_db($question->getSurvey()); if (intval($survey->getCreatedBy()) != $user->getId() && $user->getAdmin() != 1) { $error = new Error("Question PrintExcel: unathorised access"); $error->writeLog(); logout(); die; } header('Location: ' . ROOT_DIR . 'functions/print/excel/questionReport.php?question_id=' . $question_id); die; } elseif ($function == 'PrintExcelGroups') { // get global user object global $user; // get survey id $question_id = $_POST['formElementFunction']; // check if the user is the surveyCreator or systemAdmin $question = new Question(); $question->get_from_db($question_id); $survey = new Survey(); $survey->get_from_db($question->getSurvey()); if (intval($survey->getCreatedBy()) != $user->getId() && $user->getAdmin() != 1) { $error = new Error("Question PrintExcelGroups: unathorised access"); $error->writeLog(); logout(); die; } header('Location: ' . ROOT_DIR . 'functions/print/excel/questionReportGroups.php?question_id=' . $question_id); die; } elseif ($function == 'PrintExcelGender') { // get global user object global $user; // get survey id $question_id = $_POST['formElementFunction']; // check if the user is the surveyCreator or systemAdmin $question = new Question(); $question->get_from_db($question_id); $survey = new Survey(); $survey->get_from_db($question->getSurvey()); if (intval($survey->getCreatedBy()) != $user->getId() && $user->getAdmin() != 1) { $error = new Error("Question PrintExcelGender: unathorised access"); $error->writeLog(); logout(); die; } header('Location: ' . ROOT_DIR . 'functions/print/excel/questionReportGender.php?question_id=' . $question_id); die; } elseif ($function == 'PrintExcelAge') { // get global user object global $user; // get survey id $question_id = $_POST['formElementFunction']; // check if the user is the surveyCreator or systemAdmin $question = new Question(); $question->get_from_db($question_id); $survey = new Survey(); $survey->get_from_db($question->getSurvey()); if (intval($survey->getCreatedBy()) != $user->getId() && $user->getAdmin() != 1) { $error = new Error("Question PrintExcelAge: unathorised access"); $error->writeLog(); logout(); die; } header('Location: ' . ROOT_DIR . 'functions/print/excel/questionReportAge.php?question_id=' . $question_id); die; } die; }
foreach ($voted_users as $voted_user_id) { $user = new User(); $user->get_from_db($voted_user_id); $cell = 'A' . $row_id; $user_number = $row_id - 2; $cell_value = 'User' . $user_number; // Add some data $objPHPExcel->setActiveSheetIndex($sheetId)->setCellValue($cell, $cell_value); // list votes by user $columnId = 2; foreach ($question_answers as $question_answer_id) { $vote = new Vote(); $vote_id_array = $vote->get_by_user_and_answer($voted_user_id, $question_answer_id); $cell_value = ""; $answer = new Answer(); $answer->get_from_db($question_answer_id); if (!empty($vote_id_array)) { $vote_id = $vote_id_array[0]; $vote->get_from_db($vote_id); if ($answer->getType() == "radio" || $answer->getType() == "checkbox") { $cell_value = 1; } elseif ($answer->getType() == "text") { $cell_value = $vote->getValue(); } } // fill in cell $cell = divideBy26($columnId) . $row_id; // Add some data $objPHPExcel->setActiveSheetIndex($sheetId)->setCellValue($cell, $cell_value); $objPHPExcel->getActiveSheet()->getStyle($cell)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // increase column number