$('#answer').markItUp(myHtmlSettings); }); </script> <form id="form" method="post" action=""> <table> <tr id="course"> <td><label for="title">Course:</label></td> <td><?php print isset($_POST['post_cid']) ? $post_course['Course_Name'] . '<input type="hidden" name="cid" value="' . $post_cid . '" />' : select_course('cid'); ?> </td> </tr> <tr id="week"> <td><label for="title">Week:</label></td> <td><?php print select_week('week'); ?> </td> </tr> <tr> <td><label for="title">Title:</label></td> <td><input type="text" name="title" size="60" maxlength="128" class="required" /></td> </tr> <tr> <td><label for="url">URL Alias:</label></td> <td><input type="text" name="url" size="60" maxlength="128" class="required" /></td> </tr> <tr> <td><label for="body">Body:</label></td> <td><textarea id="body" cols="60" rows="20" name="body" class="required"></textarea></td> </tr>
<input type="hidden" name="pid" value="<?php print $pid; ?> "/> <table> <tr id="course"> <td><label for="type">Course:</label></td> <td><?php print select_course('cid', $old_cid); ?> </td> </tr> <tr id="week"> <td><label for="type">Week:</label></td> <td><?php print select_week('week', $old_week); ?> </td> </tr> <tr style="display:none"> <td><label for="title">Title:</label></td> <td><input type="text" name="title" value="<?php print $old_title; ?> " size="60" maxlength="128" class="required" /><input type="hidden" name="url" value="<?php print $old_url; ?> " /></td> </tr> <tr> <td><label for="body">Body:</label></td>
function ask_question($rid, $cid, $week) { $output = ''; $feeds_type = ''; if ($cid == 0 && $week == 0) { $feeds_type = 'front'; } elseif ($cid != 0 && $week == 0) { $feeds_type = 'course'; } elseif ($cid != 0 && $week != 0) { $feeds_type = 'course_week'; } elseif ($cid == 0 && $week != 0) { $feeds_type = 'week'; } $course = course_load($cid); $output .= '<div id="ask_question">'; $output .= '<div id="ask_label">Ask Question</div>'; $output .= '<div id="question_section" title="Ask question" class="' . ($rid == 0 ? 'not_loggedin' : '') . (!course_belonged($cid, $_SESSION['uid']) && $cid != 0 && $rid != 1 ? ' not_belonged' : '') . (isset($course['Course_Allowed']) && $course['Course_Allowed'] != 1 && $rid != 3 ? ' not_allowed' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 1 ? ' is_admin' : '') . (!is_enroled($_SESSION['uid']) ? ' not_enroled' : '') . (!is_allowed($_SESSION['uid']) && $rid != 1 && $rid != 3 ? ' no_course' : '') . ($rid == 4 ? ' guest_mode' : '') . '">'; $output .= '<span id="question_label">Type a question..</span>'; $output .= '<a id="question_close_button"></a>'; $output .= '<div class="question_element" style="margin-top: 5px;"><label for="question_title">Subject: </label><input class="element_input" id="question_title" name="question_title" type="text" size="30" /></div>'; $output .= '<input class="element_input" id="question_url" name="question_url" type="hidden" />'; $output .= '<div class="question_element"><label for="question_body">Type a question.. </label><br/><textarea style="resize: none; overflow: auto" class="element_textarea" id="question_body" name="question_body" rows="1"></textarea></div><br/>'; $output .= $rid != 2 && $rid != 4 ? '<div class="question_element"><label for="question_answer">Type an answer.. </label><br/><textarea style="resize: none; overflow: auto" class="element_textarea" id="question_answer" name="question_answer" rows="1"></textarea></div><br/>' : '<input type="hidden" id="question_answer" value="" />'; $output .= $rid == 2 || $rid == 4 ? '<div class="question_element"><input style="float: left;width: 20px;margin-right: 0px;margin-top: 7px;" id="question_hide" type="checkbox" name="hide" value="1" /><label for="question_hide">Hide your username from others</label></div>' : '<input id="question_hide" type="hidden" name="hide" value="0" />'; $output .= '<div id="question_bottom">'; $output .= '<div class="question_element week"><label for="question_week">Week: </label>' . ($week == 0 ? select_week('question_week') : select_week('question_week', $week)) . '</div>'; $output .= $cid == 0 ? '<div class="question_element course"><label for="question_cid">Course: </label>' . select_course('question_cid') . '</div>' : '<input type="hidden" id="question_cid" value="' . $cid . '" />'; $output .= '<a class="button ' . ($rid == 0 ? 'disabled' : '') . '" id="post_submit">Post</a>'; $output .= '</div>'; $output .= '</div>'; $output .= '<div style="display:none" id="save_post"></div>'; $output .= '<div style="display:none" id="follow_post"></div>'; $output .= '<script> $("#question_section").click(function(){ if (!$(this).hasClass("not_loggedin") && !$(this).hasClass("not_belonged") && !$(this).hasClass("not_allowed") && !$(this).hasClass("is_admin") && !$(this).hasClass("not_enroled") && !$(this).hasClass("no_course") || $(this).hasClass("guest_mode")) { $("#question_label").text(""); $("#question_section .question_element,#question_close_button,#question_bottom").css("display","block"); $(this).css("cursor","default").animate({height:"' . ($rid != 2 && $rid != 4 ? '140px' : '125px') . '"},240); } else if ($(this).hasClass("not_loggedin")) { openLogin(); } else if ($(this).hasClass("not_belonged")) { openWrap("You do not belong to this course"); } else if ($(this).hasClass("not_allowed")) { openWrap("The course(s) not allow posting"); } else if ($(this).hasClass("no_course")) { openWrap("You do not belong to any course"); } else if ($(this).hasClass("is_admin")) { openWrap("Admin cannot post question"); } else if ($(this).hasClass("not_enroled")) { openWrap("You are not enroled in any course. Please ask your lecturer to enrol you into a course"); } }); $("#question_close_button").click(function(e){ e.stopPropagation(); $("#question_label").text("Type a question.."); $("#question_section .question_element,#question_close_button,#question_bottom").css("display","none"); $("#question_section").css("cursor","text").animate({height:"27px"},240); $(".element_input").val(""); $(".element_textarea").val(""); $("#question_hide").attr("checked",false); }); $("#post_submit").click(function(){ if (!$(this).hasClass("disabled")) { var errors = ""; if ($("#question_title").val() == "") { errors += "<p>Question subject is empty.</p>"; } if ($("#question_body").val() == "") { errors += "<p>Question body is empty.</p>"; } if ($("#question_title").val() != "" && $("#question_url").val() != "" && $("#question_body").val() != "") { appendDate(); $("#save_post").load("triggers/post_create.php",{cid:$("#question_cid").val(),week:$("#question_week").val(),title:$("#question_title").val(),url:$("#question_url").val(),body:$("#question_body").val(),answer:$("#question_answer").val(),hide:$("#question_hide:checked").val()}, function(data){ if (data == "URL_EXISTS") { openWrap("Duplicated subject."); } else { $("#question_label").text("Type a question.."); $("#question_section .question_element,#question_close_button,#question_bottom").css("display","none"); $("#question_section").css("height","27px"); $("#follow_post").load("triggers/latest_post_follow.php",function(){ $("#feeds").load("triggers/feeds_update.php",{feeds_type:"' . $feeds_type . '"},function(){ $("#rightmenu").load("templates/rightmenu.tpl.php",function(){ openWrap("Post created"); }); }); }); } }); } else { openWrap(errors); $("#question_title").focus(); } } else { openLogin(); } }); function updateField(){ var title = $("input#question_title").val(); var url = title.replace(/[<>""!?,.!@#$%^&*{};:()]+/g,""); var url = url.toLowerCase(); var url = url.replace(/[^A-Za-z0-9-]+/g,"-"); $("input#question_url").val(url); } function appendDate() { var url = $("input#question_url").val(); var d = new Date(); var month = d.getMonth()+1; var day = d.getDate(); var outputDate = d.getFullYear() + "-" + (month<10 ? "0" : "") + month + "-" + (day<10 ? "0" : "") + day; var url = url + "-" + outputDate; $("input#question_url").val(url); } $("input#question_title").keyup(updateField).keydown(updateField).change(updateField); $("textarea#question_body, textarea#question_answer").keyup(function(){ limits($(this), 900); }).keydown(function(){ limits($(this), 900); }).change(function(){ limits($(this), 900); }); $("input#question_title").keyup(function(){ limits($(this), 42); }).keydown(function(){ limits($(this), 42); }).change(function(){ limits($(this), 42); }); </script>'; $output .= '</div>'; return $output; }