Пример #1
0
 function JQ_exportQuestions($option, $page, $course_id, $cid, $gqp = false)
 {
     global $JLMS_DB, $Itemid;
     $quiz_id = intval(mosGetParam($_REQUEST, 'quiz_id', 0));
     $where = "";
     if ($gqp) {
         $where .= "\n AND course_id = '0'";
         $where .= "\n AND c_quiz_id = '0'";
     } else {
         if ($quiz_id > 0) {
             $where .= "\n AND course_id = '" . $course_id . "'";
             $where .= "\n AND c_quiz_id = '" . $quiz_id . "'";
         } else {
             $where .= "\n AND course_id = '" . $course_id . "'";
             $where .= "\n AND c_quiz_id = '0'";
         }
     }
     $query = "SELECT *" . "\n FROM #__lms_quiz_t_question" . "\n WHERE 1" . $where . (count($cid) && $cid[0] ? "\n AND c_id IN (" . implode(",", $cid) . ")" : "");
     $JLMS_DB->setQuery($query);
     $questions = $JLMS_DB->loadObjectList();
     $query = "SELECT *" . "\n FROM #__lms_quiz_t_question" . "\n WHERE 1" . "\n AND course_id = '" . $course_id . "'" . "\n AND c_quiz_id = '0'";
     $JLMS_DB->setQuery($query);
     $qpool = $JLMS_DB->loadObjectList();
     $query = "SELECT *" . "\n FROM #__lms_quiz_t_question" . "\n WHERE 1" . "\n AND course_id = '0'" . "\n AND c_quiz_id = '0'";
     $JLMS_DB->setQuery($query);
     $gqpool = $JLMS_DB->loadObjectList();
     if (isset($questions) && count($questions)) {
         $tmp_questions = array();
         foreach ($questions as $n => $quest) {
             $tmp_questions[$n] = $quest;
             if ($quest->c_type == 20) {
                 if (isset($qpool) && count($qpool)) {
                     foreach ($qpool as $item_qpool) {
                         if ($quest->c_pool == $item_qpool->c_id) {
                             $tmp_questions[$n]->c_id = $item_qpool->c_id;
                             $tmp_questions[$n]->course_id = $quest->course_id;
                             $tmp_questions[$n]->c_quiz_id = $quest->c_quiz_id;
                             $tmp_questions[$n]->c_point = $item_qpool->c_point;
                             $tmp_questions[$n]->c_attempts = $item_qpool->c_attempts;
                             $tmp_questions[$n]->c_question = $item_qpool->c_question;
                             $tmp_questions[$n]->c_type = $item_qpool->c_type;
                             $tmp_questions[$n]->published = $quest->published;
                             $tmp_questions[$n]->ordering = $quest->ordering;
                         }
                     }
                 }
             }
             if ($quest->c_type == 21) {
                 if (isset($gqpool) && count($gqpool)) {
                     foreach ($gqpool as $item_gqpool) {
                         if ($quest->c_pool_gqp == $item_gqpool->c_id) {
                             $tmp_questions[$n]->c_id = $item_gqpool->c_id;
                             $tmp_questions[$n]->course_id = $quest->course_id;
                             $tmp_questions[$n]->c_quiz_id = $quest->c_quiz_id;
                             $tmp_questions[$n]->c_point = $item_gqpool->c_point;
                             $tmp_questions[$n]->c_attempts = $item_gqpool->c_attempts;
                             $tmp_questions[$n]->c_question = $item_gqpool->c_question;
                             $tmp_questions[$n]->c_type = $item_gqpool->c_type;
                             $tmp_questions[$n]->published = $quest->published;
                             $tmp_questions[$n]->ordering = $quest->ordering;
                         }
                     }
                 }
             }
         }
         if (isset($tmp_questions) && count($tmp_questions)) {
             $questions = array();
             $questions = $tmp_questions;
         }
     }
     //	echo '<pre>';
     //	print_r($qpool);
     //	print_r($gqpool);
     //	print_r($questions);
     //	echo '</pre>';
     //	die;
     $question_ids = array();
     $questions_types = array();
     foreach ($questions as $n => $question) {
         $question_ids[$n] = $question->c_id;
         $questions_types[$question->c_type][] = $question->c_id;
     }
     $variants_answers_types = array();
     foreach ($questions_types as $type => $quests) {
         switch (intval($type)) {
             case '1':
             case '2':
             case '3':
                 #case '12':
                 #case '13':
                 if (isset($quests) && count($quests)) {
                     $variants_answers = array();
                     $str_quiestions_ids = implode(",", $quests);
                     $query = "SELECT c_id, c_question_id, c_choice, c_right, ordering" . "\n FROM #__lms_quiz_t_choice" . "\n WHERE 1" . "\n AND c_question_id IN (" . $str_quiestions_ids . ")" . "\n ORDER BY c_question_id, ordering";
                     $JLMS_DB->setQuery($query);
                     $variants_answers = $JLMS_DB->loadObjectList();
                     $variants_answers_types[$type] = $variants_answers;
                 }
                 break;
             case '4':
             case '5':
                 #case '11':
                 if (isset($quests) && count($quests)) {
                     $variants_answers = array();
                     $str_quiestions_ids = implode(",", $quests);
                     $query = "SELECT *" . "\n FROM #__lms_quiz_t_matching" . "\n WHERE 1" . "\n AND c_question_id IN (" . $str_quiestions_ids . ")" . "\n ORDER BY c_question_id, ordering";
                     $JLMS_DB->setQuery($query);
                     $variants_answers = $JLMS_DB->loadObjectList();
                     $variants_answers_types[$type] = $variants_answers;
                 }
                 break;
             case '6':
                 if (isset($quests) && count($quests)) {
                     $variants_answers = array();
                     $str_quiestions_ids = implode(",", $quests);
                     $query = "SELECT qtb.c_id, qtb.c_question_id, qtt.c_blank_id, qtt.c_text, qtt.ordering" . "\n FROM #__lms_quiz_t_blank qtb, #__lms_quiz_t_text as qtt" . "\n WHERE 1" . "\n AND qtb.c_question_id IN (" . $str_quiestions_ids . ")" . "\n AND qtb.c_id = qtt.c_blank_id" . "\n ORDER BY c_question_id, ordering";
                     $JLMS_DB->setQuery($query);
                     $variants_answers = $JLMS_DB->loadObjectList();
                     $variants_answers_types[$type] = $variants_answers;
                 }
                 break;
             case '9':
                 if (isset($quests) && count($quests)) {
                     $variants_answers = array();
                     $str_quiestions_ids = implode(",", $quests);
                     $query = "SELECT *" . "\n FROM #__lms_quiz_t_scale" . "\n WHERE 1" . "\n AND c_question_id IN (" . $str_quiestions_ids . ")" . "\n ORDER BY c_question_id, c_type, ordering";
                     $JLMS_DB->setQuery($query);
                     $variants_answers = $JLMS_DB->loadObjectList();
                     $variants_answers_types[$type] = $variants_answers;
                 }
                 break;
         }
     }
     $max_items = 0;
     $exclude_fields = array('c_id', 'c_question_id', 'c_blank_id', 'c_right', 'ordering');
     $questions_pre_csv = array();
     foreach ($questions as $n => $quest) {
         if (isset($variants_answers_types[$quest->c_type]) && count($variants_answers_types[$quest->c_type])) {
             $questions_pre_csv[$n] = $quest;
             $v_answers = $variants_answers_types[$quest->c_type];
             $questions_pre_csv[$n]->answers = array();
             $i = 0;
             $max_fields = 0;
             foreach ($v_answers as $v_answ) {
                 if ($v_answ->c_question_id == $quest->c_id) {
                     $questions_pre_csv[$n]->answers[] = $v_answ;
                     if (!$i) {
                         $cfields = 0;
                         foreach ($v_answ as $key => $item) {
                             if (!in_array($key, $exclude_fields)) {
                                 $cfields++;
                             }
                         }
                     }
                     $i++;
                     $max_fields = $cfields * $i;
                 }
             }
             if ($max_items < $max_fields) {
                 $max_items = $max_fields;
             }
         }
     }
     $question_csv = array();
     foreach ($questions_pre_csv as $n => $qpcsv) {
         $question_csv[$n]->type = JLMS_quiz_admin_class::getQuestType($qpcsv->c_type);
         $question_csv[$n]->question = JLMS_processCSVField($qpcsv->c_question);
         $question_csv[$n]->points = $qpcsv->c_point;
         $question_csv[$n]->attempts = $qpcsv->c_attempts;
         $question_csv[$n]->published = $qpcsv->published;
         $question_csv[$n]->ordering = $qpcsv->ordering;
         $question_csv[$n]->right = JLMS_processCSVField(JLMS_quiz_admin_class::getRight($qpcsv->c_type, $qpcsv->answers));
         if (isset($qpcsv->answers) && count($qpcsv->answers)) {
             $tmp_answers = $qpcsv->answers;
             $m = 1;
             foreach ($tmp_answers as $tmp_a) {
                 foreach ($tmp_a as $key => $item) {
                     $answ_item = 'item_' . $m;
                     if (!in_array($key, $exclude_fields)) {
                         $question_csv[$n]->{$answ_item} = JLMS_processCSVField($item);
                         $m++;
                     }
                 }
             }
             if ($m < $max_items) {
                 for ($i = $m; $i <= $max_items; $i++) {
                     $answ_item = 'item_' . $i;
                     $question_csv[$n]->{$answ_item} = JLMS_processCSVField('');
                 }
             }
             /*
             for($i=0;$i<$max_items;$i++){
             	$m = $i + 1;
             	$answ_item = 'item_'.$m;
             	
             	if(isset($tmp_answers[$i])){
             		switch(intval($qpcsv->c_type)){
             			case '1':
             			case '2':
             			case '3':
             				$question_csv[$n]->$answ_item = $tmp_answers[$i]->c_choice;
             			break;
             			case '4':
             			case '5':
             				$question_csv[$n]->$answ_item = $tmp_answers[$i]->c_left_text;
             			break;	
             			case '6':
             				$question_csv[$n]->$answ_item = $tmp_answers[$i]->c_text;
             			break;
             			case '9':
             				$question_csv[$n]->$answ_item = $tmp_answers[$i]->c_field;
             			break;	
             		}
             	} else {
             		$question_csv[$n]->$answ_item = '';
             	}
             }
             */
         }
     }
     $titles = new stdClass();
     $titles->type = _JLMS_QUIZ_TBL_QUEST_TYPE;
     //'Type';
     $titles->question = str_replace(':', '', _JLMS_QUIZ_QUESTION);
     //'Question';
     $titles->points = str_replace(':', '', _JLMS_QUIZ_QUEST_POINTS);
     //'Points';
     $titles->attempts = str_replace(':', '', _JLMS_QUIZ_QUEST_ATTEMPTS);
     //'Attempts';
     $titles->published = _JLMS_QUIZ_TBL_QUEST_PUBLISH;
     //'Published';
     $titles->ordering = str_replace(':', '', _JLMS_QUIZ_QUEST_ORDERING);
     //'Ordering';
     $titles->right = 'Correct choice';
     for ($i = 1; $i <= $max_items; $i++) {
         $titles->{'item_' . $i} = 'Item ' . $i;
     }
     $data_csv = '';
     $titles = get_object_vars($titles);
     if (isset($titles) && count($titles)) {
         foreach ($titles as $tk => $tv) {
             $titles[$tk] = JLMS_processCSVField($tv);
         }
         $data_csv .= implode(",", $titles) . "\n";
     }
     if (count($question_csv)) {
         foreach ($question_csv as $n => $d) {
             $d = get_object_vars($d);
             $data_csv .= implode(",", $d) . "\n";
         }
     }
     if ($course_id > 0 && $quiz_id > 0) {
         $course_name = JLMS_getCourseName($course_id);
         $quiz_name = JLMS_getQuizName($quiz_id);
         $tmpl_name = ucfirst($course_name) . '_[' . ucfirst($quiz_name) . ']_' . date('dMY');
     } else {
         if ($course_id > 0 && $quiz_id < 0) {
             $course_name = JLMS_getCourseName($course_id);
             $tmpl_name = ucfirst($course_name) . '_[' . _JLMS_QUIZ_QUEST_POOL . ']_' . date('dMY');
         } else {
             $tmpl_name = _JLMS_GLOBAL_QUEST_POOL . '_' . date('dMY');
         }
     }
     $tmpl_name = str_replace(" ", "_", $tmpl_name);
     if (preg_match('/Opera(\\/| )([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
         $UserBrowser = "Opera";
     } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
         $UserBrowser = "IE";
     } else {
         $UserBrowser = '';
     }
     header("Content-type: application/csv");
     header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header("Content-Length: " . strlen(trim($data_csv)));
     header('Content-Disposition: attachment; filename="' . $tmpl_name . '.csv"');
     if ($UserBrowser == 'IE') {
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         header('Pragma: no-cache');
     }
     echo $data_csv;
     exit;
     echo '<pre>';
     print_r($max_items);
     //	print_r($_POST);
     //	print_r($JLMS_DB->getQuery());
     //	print_r($JLMS_DB->getErrorMsg());
     //	print_r($variants_answers);
     //	print_r($variants_answers_types);
     //	print_r($questions);
     //	print_r($questions_pre_csv);
     print_r($question_csv);
     //	print_r($question_ids);
     //	print_r($questions_types);
     echo '</pre>';
     die;
 }
    function JLMS_showOutbox($row, $course_id, $pageNav, $option, $m_count)
    {
        global $Itemid, $JLMS_DB, $JLMS_CONFIG;
        JLMS_TMPL::OpenMT();
        if (!$course_id) {
            $hparams = array('show_menu' => false);
        } else {
            $hparams = array();
        }
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'mail_inbox', 'btn_js' => "javascript:submitbutton('mailbox');");
        $toolbar[] = array('btn_type' => 'mail_outbox', 'btn_js' => "javascript:submitbutton('mail_sendbox');");
        $toolbar[] = array('btn_type' => 'mail_send', 'btn_js' => "javascript:submitbutton('mailbox_new');");
        $outbox_title = _JLMS_MB_OUTBOX;
        $outbox_title = str_replace('Y', $m_count, $outbox_title);
        JLMS_TMPL::ShowHeader('mailbox', $outbox_title, $hparams, $toolbar);
        JLMS_TMPL::OpenTS();
        ?>
		<script type="text/javascript">
		function submitbutton(pressbutton) {
			var form = document.adminForm;

				if ((pressbutton == 'mail_delete') && (form.boxchecked.value == "0")){
					alert( "<?php 
        echo _JLMS_MB_SEL_ITEM;
        ?>
" );
				} else {
					form.task.value = pressbutton;
					form.submit();
				}

		}
		</script>
		<form action="<?php 
        echo sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}");
        ?>
" method="post" name="adminForm">
		<table width="100%" cellpadding="2" cellspacing="0" border="0" class="<?php 
        echo JLMSCSS::_('jlmslist');
        ?>
">
			<tr>
				<<?php 
        echo JLMSCSS::tableheadertag();
        ?>
  class="<?php 
        echo JLMSCSS::_('sectiontableheader');
        ?>
" width="20">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php 
        echo count($row);
        ?>
);" />
					<!-- checkbox -->
				</<?php 
        echo JLMSCSS::tableheadertag();
        ?>
>

				<<?php 
        echo JLMSCSS::tableheadertag();
        ?>
 class="<?php 
        echo JLMSCSS::_('sectiontableheader');
        ?>
">
					<?php 
        echo _JLMS_MB_TO;
        ?>
				</<?php 
        echo JLMSCSS::tableheadertag();
        ?>
>
				<<?php 
        echo JLMSCSS::tableheadertag();
        ?>
 class="<?php 
        echo JLMSCSS::_('sectiontableheader');
        ?>
">
					<?php 
        echo _JLMS_MB_SUBJECT;
        ?>
				</<?php 
        echo JLMSCSS::tableheadertag();
        ?>
>
				<<?php 
        echo JLMSCSS::tableheadertag();
        ?>
 class="<?php 
        echo JLMSCSS::_('sectiontableheader');
        ?>
">
					<?php 
        echo _JLMS_MB_DATE;
        ?>
				</<?php 
        echo JLMSCSS::tableheadertag();
        ?>
>
			</tr>
			<?php 
        for ($i = 0; $i < count($row); $i++) {
            $link = sefreltoabs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=mail_view&amp;view_id=" . $row[$i]->id . "&amp;id={$course_id}&amp;inb=1");
            $checked = '<input type="checkbox" id="cb' . $i . '" name="cid[]" value="' . $row[$i]->id . '" onclick="isChecked(this.checked);" />';
            $query = "SELECT u.username FROM #__lms_messages_to as mt, #__users as u WHERE mt.id=" . $row[$i]->id . " AND u.id=mt.user_id";
            $JLMS_DB->setQuery($query);
            $userki = $JLMS_DB->loadResultArray();
            $userz = implode(', ', $userki);
            $userz = strlen($userz) > 20 ? substr($userz, 0, 18) . '...' : $userz;
            echo '<tr class="' . JLMSCSS::_('sectiontableentry' . ($i % 2 + 1)) . '">';
            echo '<td>' . $checked . '</td>';
            echo '<td>' . $userz . '</td>';
            echo '<td><a href="' . $link . '">' . stripslashes(strlen($row[$i]->subject) > 40 ? substr($row[$i]->subject, 0, 38) . '...' : $row[$i]->subject) . '</a>';
            if ($row[$i]->course_id) {
                echo '<br /><span class="small">' . _JLMS_MB_COURSE_NAME . ': ' . JLMS_getCourseName($row[$i]->course_id) . '</span>';
            }
            echo '</td>';
            echo '<td>' . $row[$i]->data . '</td>';
            echo '</tr>';
        }
        ?>
			<tr>
			<td colspan="7" align="center" class="<?php 
        echo JLMSCSS::_('jlmslist-footer_td');
        ?>
"><div align="center">
				<?php 
        $link = "index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=mail_sendbox&amp;id={$course_id}";
        echo _JLMS_PN_DISPLAY_NUM . $pageNav->getLimitBox($link) . ' ' . $pageNav->getPagesCounter();
        echo '<br />';
        echo $pageNav->writePagesLinks($link);
        ?>
				
			</div></td>
		</tr>
		</table>
		<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
		<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
		<input type="hidden" name="task" value="mail_sendbox" />
		<input type="hidden" name="id" value="<?php 
        echo $course_id;
        ?>
" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="state" value="0" />
		<input type="hidden" name="sendbox" value="1" />
		</form>
		<?php 
        JLMS_TMPL::CloseTS();
        $controls = array();
        $controls[] = array('href' => "javascript:submitbutton('mail_delete');", 'title' => _JLMS_DELETE, 'img' => 'delete');
        JLMS_TMPL::ShowControlsFooter($controls);
        //, sefRelToAbs("index.php?option=$option&amp;Itemid=$Itemid&amp;task=mail_sendbox&amp;id=$course_id"));
        JLMS_TMPL::CloseMT();
    }