Exemplo n.º 1
0
function print_answers($id, $level, $visited = false)
{
    // Print "conversation" for a given note
    global $db;
    if (!$visited) {
        $visited = array();
        $visited[] = $id;
    }
    $printed = array();
    $answers = $db->get_col("SELECT conversation_from FROM conversations WHERE conversation_type='post' and conversation_to = {$id} ORDER BY conversation_from asc LIMIT 100");
    $parent_reference = "/@\\p{L}[\\._\\p{L}\\d]+,{$id}/ui";
    // To check that the notes references to $id
    if ($answers) {
        echo '<div style="padding-left: 5%; padding-top: 5px;">';
        echo '<ol class="comments-list">';
        foreach ($answers as $post_id) {
            if (in_array($post_id, $visited)) {
                continue;
            }
            $answer = Post::from_db($post_id);
            if (!$answer) {
                continue;
            }
            if ($answer->user_level == 'autodisabled' || $answers->user_level == 'disabled') {
                continue;
            }
            // Check the post has a real reference to the parent (with the id), ignore othewrise
            if (!preg_match($parent_reference, $answer->content)) {
                continue;
            }
            echo '<li>';
            $answer->print_summary();
            echo '</li>';
            if ($level > 0) {
                $res = print_answers($answer->id, $level - 1, array_merge($visited, $answers));
                $visited = array_merge($visited, $res);
            }
            $printed[] = $answer->id;
            $visited[] = $answer->id;
        }
        echo '</ol>';
        echo '</div>';
        if ($level == 0) {
            Haanga::Load('get_total_answers_by_ids.html', array('type' => 'post', 'ids' => implode(',', $printed)));
        }
    }
    return $printed;
}
Exemplo n.º 2
0
function print_answers($id, $level, $visited = false)
{
    // Print answers to the comment
    global $db, $page_size;
    if (!$visited) {
        $visited = array();
        $visited[] = $id;
    }
    $printed = array();
    $sql = "SELECT conversation_from FROM conversations, comments WHERE conversation_type='comment' and conversation_to = {$id} and comment_id = conversation_from ORDER BY conversation_from asc LIMIT {$page_size}";
    $answers = $db->get_col($sql);
    if ($answers) {
        $type = 'comment';
        echo '<div style="padding-left: 6%">' . "\n";
        echo '<ol class="comments-list">';
        foreach ($answers as $dbanswer) {
            if (in_array($dbanswer, $visited)) {
                continue;
            }
            $answer = Comment::from_db($dbanswer);
            $answer->url = $answer->get_relative_individual_permalink();
            echo '<li>';
            $answer->print_summary($link);
            if ($level > 0) {
                $res = print_answers($answer->id, $level - 1, array_merge($visited, $answers));
                $visited = array_merge($visited, $res);
            }
            $printed[] = $answer->id;
            $visited[] = $answer->id;
            echo '</li>';
        }
        echo "</ol>\n";
        echo '</div>' . "\n";
        if ($level == 0) {
            $ids = implode(',', $printed);
            Haanga::Load('get_total_answers_by_ids.html', compact('type', 'ids'));
        }
    }
    return $printed;
}
Exemplo n.º 3
0
function ssquiz_print_questions($offset, $quiz_id)
{
    global $wpdb;
    if (!current_user_can(SSQUIZ_CAP)) {
        return;
    }
    if (isset($_GET['quiz_id']) && $_GET['quiz_id'] > '') {
        $quiz_id = intval($_GET['quiz_id']);
    }
    if ($offset === NULL) {
        $offset = -1;
    }
    if ($quiz_id === NULL) {
        $quiz_id = -1;
    }
    $temp = get_option('ssquiz_page');
    if ($quiz_id == -1) {
        $quiz_id = $temp->quiz_id;
    }
    if ($temp->quiz_id != $quiz_id) {
        $offset = 0;
    } else {
        if ($offset == -1) {
            $offset = $temp->offset;
        }
    }
    $temp->offset = $offset;
    $temp->quiz_id = $quiz_id;
    update_option('ssquiz_page', $temp);
    $total_questions = $wpdb->get_var("SELECT count(*) FROM {$wpdb->base_prefix}ssquiz_questions");
    $total_quizzes = $wpdb->get_var("SELECT count(*) FROM {$wpdb->base_prefix}ssquiz_quizzes");
    $max = 20;
    $temp = $quiz_id != 0 ? "WHERE quizzes.id = {$quiz_id}" : '';
    $total_questions_in_list = $wpdb->get_var("SELECT count(*) \n\t\t\t\tFROM {$wpdb->base_prefix}ssquiz_quizzes as quizzes LEFT JOIN {$wpdb->base_prefix}ssquiz_questions as questions \n\t\t\t\tON questions.quiz_id = quizzes.id {$temp}");
    $sql = "SELECT quizzes.id as quiz_id, quizzes.name as quiz_name, quizzes.meta as quiz_meta, questions.number as number, questions.type as type,\n\t\t\t\t\tquestions.question as question, questions.meta as questions_meta, questions.answers as answers, questions.id as id\n\t\t\t\tFROM {$wpdb->base_prefix}ssquiz_quizzes as quizzes LEFT JOIN {$wpdb->base_prefix}ssquiz_questions as questions \n\t\t\t\tON questions.quiz_id = quizzes.id\n\t\t\t\t{$temp}\n\t\t\t\tORDER BY quiz_id, number ASC LIMIT {$offset}, {$max};";
    $questions = $wpdb->get_results($sql);
    $quiz_id = -1;
    ?>
	<div class="pagination pagination-centered" style="margin: 0 auto 10px 0;">
		<ul>
			<li class="<?php 
    if ($offset == 0) {
        echo 'disabled';
    }
    ?>
">
				<a href="#" onclick="jQuery.fn.go_to_page(<?php 
    echo $offset - $max;
    ?>
)"><?php 
    echo __("Prev", 'ssquiz');
    ?>
</a></li>
			<?php 
    for ($i = 0; $i * $max < intval($total_questions_in_list); $i++) {
        ?>
<li class="<?php 
        echo $offset == $i * $max ? 'disabled' : '';
        ?>
" >
					<a href='#' onclick='jQuery.fn.go_to_page(<?php 
        echo $i * $max;
        ?>
)'><?php 
        echo $i + 1;
        ?>
</a>
				</li><?php 
    }
    ?>
<li class="<?php 
    if (intval($total_questions_in_list) <= $offset + $max) {
        echo 'disabled';
    }
    ?>
">
				<a href="#" onclick="jQuery.fn.go_to_page(<?php 
    echo $offset + $max;
    ?>
)"><?php 
    echo __("Next", 'ssquiz');
    ?>
</a></li>	
		</ul>
	</div>
	<ul id="ssquiz_sortable">
	<?php 
    foreach ($questions as $question) {
        //print quiz
        try {
            if ($question->quiz_id != $quiz_id) {
                ?>
	<li class='ui-state-default ui-state-disabled row'>
				<div class="sdiv1"><span class="badge badge-info">id=<?php 
                echo $question->quiz_id;
                ?>
</span></div>
				<div class="sdiv2" style="font-style: italic;"><?php 
                echo $question->quiz_name;
                ?>
</div>
				<div class="sdiv2">
					<a class="btn btn-primary" href="#" onclick="jQuery.fn.crud_quiz( 'question', 'add', <?php 
                echo $question->quiz_id;
                ?>
 );return false;"
						data-toggle="modal" data-target="#ssquiz_question_modal">
						<i class="icon-plus-sign"></i> <?php 
                echo __("Add Question", 'ssquiz');
                ?>
</a>
					<a class="btn btn-primary"  onclick="jQuery.fn.crud_quiz( 'quiz', 'read', <?php 
                echo $question->quiz_id;
                ?>
 );return false;"
						data-toggle="modal" data-target="#ssquiz_quiz_modal">
						<i class="icon-pencil"></i> <?php 
                echo __("Edit", 'ssquiz');
                ?>
</a>
				</div>
			</li>
			<?php 
                $quiz_id = $question->quiz_id;
            }
            //print question
            if (!isset($question->id)) {
                continue;
            }
            $temp = esc_html($question->question);
            if (strlen($temp) > 100) {
                $temp = substr($temp, 0, 97) . '...';
            }
            ?>
	<li class='ui-state-default row' 
					data-id="<?php 
            echo $question->id;
            ?>
" 
					data-quiz_id="<?php 
            echo $question->quiz_id;
            ?>
"
					data-number="<?php 
            echo $question->number;
            ?>
">
			<div class="sdiv1"><?php 
            echo $question->number;
            ?>
</div>
			<div class="sdiv2"><?php 
            echo $temp;
            ?>
<span class="label"><?php 
            echo $question->type;
            ?>
</span></div>
			<div class="sdiv2"><?php 
            print_answers(unserialize($question->answers), $question->type);
            ?>
</div>
			<div class="sdiv3">
			<a class="btn btn-primary" href="#" onclick="jQuery.fn.crud_quiz( 'question', 'read', <?php 
            echo $question->id;
            ?>
 );return false;"
				data-toggle="modal" data-target="#ssquiz_question_modal">
				<i class="icon-pencil"></i> <?php 
            echo __("Edit", 'ssquiz');
            ?>
</a>
			</div>
		</li>
		<?php 
        } catch (Exception $e) {
            echo $e->getMessage(), "\n";
        }
    }
    ?>
	</ul> <!-- #ssquiz_sortable -->
	<div class="ssquiz_inforamtion">
		<span>Total Quizzes: <?php 
    echo $total_quizzes;
    ?>
</span>
		<span style="margin-left:10px;"> Total Questions:  <?php 
    echo $total_questions;
    ?>
</span>
	</div>
	<?php 
    return;
}