관리-도구
편집 파일: CFCourse_section.php
<?php if (!class_exists('CFCourse_section')) { class CFCourse_section { var $loader; function __construct($arr) { $this->loader = $arr['loader']; } public function addPosition($all_position = null, $action = "all", $c_id = 0) { global $mysqli; global $dbpref; $table = $dbpref . "section"; $table2 = $dbpref . "content_options"; if ($action == "s") { $cid = $c_id; foreach ($all_position as $s_key => $sp) { $s_key = $s_key + 1; $sec_pos = $cid . $s_key; $s_stmt = $mysqli->query("UPDATE `" . $table . "` SET `section_position_id`=$sec_pos, `display_order`=$s_key WHERE `id`=" . $sp); } } else if ($action == "l") { $cid = $c_id; foreach ($all_position as $o_key => $op) { $o_key = $o_key + 1; $lec_pos = $cid . $o_key; $c_stmt = $mysqli->query("UPDATE `" . $table2 . "` SET `content_position_id`=$lec_pos, `display_order`=$o_key WHERE `id`=" . $op); } } else { $course_id = $mysqli->real_escape_string($all_position['course_id']); $positions = json_decode($all_position['pos']); $s_pos = $positions[0]; $o_pos = $positions[1]; foreach ($s_pos as $s_key => $sp) { $s_key = $s_key + 1; $sec_pos = $course_id . $s_key; $s_stmt = $mysqli->query("UPDATE `" . $table . "` SET `section_position_id`=$sec_pos, `display_order`=$s_key WHERE `id`=" . $sp); } foreach ($o_pos as $o_key => $op) { $o_key = $o_key + 1; $lec_pos = $course_id . $o_key; $c_stmt = $mysqli->query("UPDATE `" . $table2 . "` SET `content_position_id`=$lec_pos, `display_order`=$o_key WHERE `id`=" . $op); } if ($mysqli->error == 0 || $mysqli->error == "" || $mysqli->error == null) { echo json_encode(array("status" => 1, "type" => "position_add", "message" => " saved changes ")); die(); } else { echo json_encode(array("status" => 0, "type" => "position_add", "message" => "saved not changes ")); die(); } } } /* @param working: this function add section for cousrse */ public function handleSectionData($section_data = null) { global $mysqli; global $dbpref; $table = $dbpref . "section"; $install_url = get_option("install_url"); $m_action = $mysqli->real_escape_string(trim($section_data['cfcourse_s_a'])); if ($m_action == "save") { $title = $mysqli->real_escape_string(trim($section_data['cfcourse_seciton'])); $course_id = $mysqli->real_escape_string(trim($section_data['cfcourse_course_id'])); $action = $mysqli->real_escape_string(trim($section_data['cfcourse_section_action'])); $position = $mysqli->real_escape_string(trim($section_data['position'])); $positions = explode(",", $position); $pos = []; $time = date("Y-m-d H:i:s"); if (empty($title)) { json_encode(array("status" => 0, "type" => "section_title", "message" => "Please fill this field")); die(); } $etitle = $title; if ($action == "save_section") { $total_count = getTotalCount($table); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 1) { echo json_encode(array("status" => 0, "type" => "section_add", "message" => "course section not added succesfull")); die(); } $a_stmt = $mysqli->query("INSERT INTO `" . $table . "` (`course_id`, `title`,`created_at`, `updated_at`,`updates`) VALUES ($course_id, '" . $etitle . "','" . $time . "','" . $time . "','1')"); if ($mysqli->affected_rows == 1) { $last_id = $mysqli->insert_id; foreach ($positions as $posit) { if ($posit == "new") { $pos[] = $last_id; } else { $pos[] = $posit; } } $this->addPosition($pos, "s", $course_id); $html = $this->getSectionHtml($last_id, 1, "add"); echo json_encode(array("status" => 1, "type" => "section_add", "section_id" => $last_id, "data" => $html, "message" => "course section added succesfull")); die(); } else { echo json_encode(array("status" => 0, "type" => "section_add", "message" => "course section not added succesfull")); die(); } } elseif ($action == "update_section") { $section_id = $mysqli->real_escape_string(trim($section_data['cfcourse_section_id'])); $u_stmt = "UPDATE `" . $table . "` SET `title`='" . $etitle . "', `updated_at`='" . $time . "' WHERE `id`=" . $section_id; $r_u = $mysqli->query($u_stmt) ? 1 : -1; if ($r_u) { foreach ($positions as $posit) { if ($posit == "new") { $pos[] = $section_id; } else { $pos[] = $posit; } } $this->addPosition($pos, "s", $course_id); $s_title = htmlspecialchars(stripslashes($etitle)); echo json_encode(array("status" => 1, "type" => "section_update", "section_id" => $section_id, "text" => $s_title, "message" => "course section updated succesfull")); die(); } else { echo json_encode(array("status" => 0, "type" => "section_update", "message" => "course section not updated succesfull")); die(); } } } elseif ($m_action == "delete") { $table2 = $dbpref . "content_options"; $section_id = $mysqli->real_escape_string(trim($section_data['cfcourse_section_id'])); $delete_row = "DELETE FROM `" . $table . "` WHERE `id`=" . $section_id; $mysqli->query($delete_row); if ($mysqli->error == 0 || $mysqli->error == "" || $mysqli->error == null) { echo json_encode(array("status" => 1, "type" => "section_deleted", "message" => "course section deleted succesfull")); die(); } else { echo json_encode(array("status" => 0, "type" => "section_deleted", "message" => "course section not deleted succesfull")); die(); } } } public function getSectionHtml($last_id = null, $next_count = 1, $send_action = "") { global $mysqli; global $dbpref; $table = $dbpref . "section"; $r = $mysqli->query("SELECT * FROM `" . $table . "` Where `id`=" . $last_id); $html = ""; if ($r->num_rows > 0) { $s_data = $r->fetch_assoc(); $s_text = htmlspecialchars(stripslashes($s_data['title'])); $s_tex = (strlen($s_text) > 120) ? substr($s_text, 0, 120) . '...' : $s_text; $course_id = $s_data['course_id']; if ($send_action == "add") { $html .= '<input class="cfcourse-section-position" type="hidden" data-cfcid="' . $course_id . '" data-cfsid="' . $last_id . '" name="cfcourseSitem[]" value="' . ($next_count + 1) . '"> <div class="cfcourse-s p-1 px-sm-2 py-2 cf--c--srtab" data-position="not" id="cfcourse-s-' . $last_id . '" data-sid="' . $last_id . '" > <div class="cfcource-section cf--c--srtab" tabindex="-1"> <div class="cfcourse-section-c cf--c--srtab"> <div class="d-flex justify-content-between justify-content-md-between flex-column flex-sm-row"> <div class="cfcourse-ff"> <span style="font-weight:bold" >' . t('Section') . '. <span class="cfcourse-s-count" style="font-weight:bold">' . ($next_count + 1) . '</span>:</span> <span class="cfcourse-s-t-t" > ' . $s_tex . ' <span> </div> <div class="cfcourse-s-action cfcourse-s-action cfcourse-s-action p-sm-0 pt-1 align-self-sm-end align-self-center"> <div class="d-flex"> <div class="px-1 cfcourse-open-s-btn" data-bs-toggle="collapse" data-bs-target="#cf-course-secop-' . $last_id . '"><button class=" cfcourse-open-s-btn btn btn-primary d-inline-block" title="' . t('Open Section') . '"> <i class="fas fa-angle-down cfcourse-s-d-arr d-inline-block cfcourse-open-s-btn" ></i></button></div> <div class="px-1 cfcourse-edit-s-btn"> <button class="cfcourse-edit-s-btn btn btn-success d-inline-block" title="' . t('Edit Section') . '"> <i class="fas fa-edit d-inline-block cfcourse-edit-s-btn"></i> </button></div> <div class="px-1 cfcourse-del-s-btn cfcourse-del-s" data-s-id="' . $last_id . '"><button class="cfcourse-del-s-btn btn btn-danger" title="' . t('Delete Section') . '"> <i class="fas fa-trash cfcourse-del-s-btn"></i> </button></div> </div> </div> </div> </div> <div class="cfcourse-update-s-d"> <div class="cfcourse-s-d "> <form action="" class="cfcourse-add-section" method="" autocomplete="off"> <input type="hidden" name="cfcourse_section_action" value="update_section" /> <input type="hidden" name="cfcourse_section_id" value="' . $last_id . '" /> <input type="hidden" name="cfcourse_course_id" value="' . $course_id . '" /> <p class="p-1 text-primary text-center font-weight-bold">' . t('Update Section') . ' </p> <div class="mb-3 mb-1 "> <label class="text-primary font-weight-bold" >' . t('Title') . '*</label> <div > <input type="text" required placeholder="' . t('Title') . '" value="' . $s_text . '" name="cfcourse_seciton" class="flex-2 form-control cfcourse_a_t_i" /> </div> </div> <div class="cfcourse-title-e cfcourse-error"> </div> <div class="text-center mt-3 d-flex justify-content-center"> <div class="mx-1"> <button type="button" class="btn btn-danger cfcourse-cancel-s-btn">' . t('Cancel') . '</button> </div> <div class="mx-1"> <button type="submit" class="btn btn-primary">' . t('Save Changes') . '</button> </div> </div> </form> </div> </div> </div> <div class="cfcourse-options-f-c collapse" id="cf-course-secop-' . $last_id . '"> <div class="cfcourse-o-a-o cfcourse-a-o cfcourse-a-a-t text-center mt-4" data-c-id="' . $course_id . '" data-s-id="' . $last_id . '"> <div class="cfcourse-a-o cfcourse-a-o-c "><button class="btn btn-primary cfcourse-a-o cfcourse-a-o-btn" title="' . t('Add Content') . '"> <span class="cfcourse-a-o cfcourse-a-o-text">+</span></button></div> </div> <div class="cfcourse-options-c cfcourse-options-sortable px-5"> </div> </div> </div> <div class="cfcourse-add-section-c text-center mt-4" data-c-id="' . $course_id . '"> <div class="cfcourse-a-s-c cfcourse-o-a-s p-1"><button class="btn btn-primary cfcourse-o-a-s" title="' . t('Add Section') . '">+</button></div> </div>'; } else if ($send_action == "update") { $html .= ' <div class="cfcourse-section-c cf--c--srtab"> <div class="d-flex justify-content-between justify-content-md-between flex-column flex-sm-row"> <div class="cfcourse-ff"> <span style="font-weight:bold" >' . t('Section') . '. <span class="cfcourse-s-count" style="font-weight:bold">' . ($next_count + 1) . '</span>:</span> <span class="cfcourse-s-t-t" > ' . $s_tex . ' <span> </div> <div class="cfcourse-s-action cfcourse-s-action cfcourse-s-action p-sm-0 pt-1 align-self-sm-end align-self-center"> <div class="d-flex"> <div class="px-1 cfcourse-open-s-btn" ><button class=" cfcourse-open-s-btn btn btn-primary d-inline-block" title="' . t('Open Section') . '"> <i class="fas fa-angle-down cfcourse-s-d-arr d-inline-block cfcourse-open-s-btn" ></i></button></div> <div class="px-1 cfcourse-edit-s-btn"> <button class="cfcourse-edit-s-btn btn btn-success d-inline-block" title="' . t('Edit Section') . '"> <i class="fas fa-edit d-inline-block cfcourse-edit-s-btn"></i> </button></div> <div class="px-1 cfcourse-del-s-btn cfcourse-del-s" data-s-id="' . $last_id . '"><button class="cfcourse-del-s-btn btn btn-danger" title="' . t('Delete Section') . '"> <i class="fas fa-trash-alt cfcourse-del-s-btn"></i> </button></div> </div> </div> </div> </div> <div class="cfcourse-update-s-d"> <div class="cfcourse-s-d "> <form action="" class="cfcourse-add-section" method="" autocomplete="off"> <input type="hidden" name="cfcourse_section_action" value="update_section" /> <input type="hidden" name="cfcourse_section_id" value="' . $last_id . '" /> <input type="hidden" name="cfcourse_course_id" value="' . $course_id . '" /> <p class="p-1 text-primary text-center font-weight-bold">' . t('Update Section') . ' </p> <div class="mb-3 mb-1 "> <label class="text-primary font-weight-bold" >' . t('Title') . '*</label> <div > <input type="text" required placeholder="' . t('Title') . '" value="' . $s_text . '" name="cfcourse_seciton" class="flex-2 form-control cf-course-sec-edit cfcourse_a_t_i" /> </div> </div> <div class="cfcourse-title-e cfcourse-error"> </div> <div class="text-center mt-3 d-flex justify-content-center"> <div class="mx-1"> <button type="button" class="btn btn-danger cfcourse-cancel-s-btn">' . t('Cancel') . '</button> </div> <div class="mx-1"> <button type="submit" class="btn btn-primary">' . t('Save Changes') . '</button> </div> </div> </form> </div> </div> '; } } return $html; } public function getCourseDetails($course_id) { global $mysqli; global $dbpref; $table = $dbpref . "all_products"; $r = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `id`=" . $course_id); if ($r->num_rows > 0) { $d = $r->fetch_assoc(); return $d; } else { return ""; } } public function getSectionData($course_id = null) { global $mysqli; global $dbpref; $table = $dbpref . "section"; $r = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `course_id`=$course_id ORDER BY `display_order` ASC LIMIT 5"); $r_d = []; if ($r->num_rows > 0) { while ($s_data = $r->fetch_assoc()) { $r_d[] = $s_data; } return $r_d; } else { return []; } } public function getSectionCount($course_id = null) { global $mysqli; global $dbpref; $table = $dbpref . "section"; $r = $mysqli->query("SELECT COUNT(*) AS 'total' FROM `" . $table . "` WHERE `course_id`=$course_id"); $r_d = []; if ($r->num_rows > 0) { $s_data = $r->fetch_assoc(); return $s_data['total']; } else { return 0; } } public function getSectionDataAjax($data = null) { global $mysqli; global $dbpref; $content = $this->loader->load("lecture"); $quiz = $this->loader->load("quiz"); $assign = $this->loader->load("assignment"); $content = $this->loader->load("lecture"); $course_id = $mysqli->real_escape_string($data['course_id']); $section_id = $mysqli->real_escape_string($data['section_id']); $table = $dbpref . "section"; $r = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `course_id`=$course_id AND `section_position_id`>$section_id ORDER BY `display_order` ASC LIMIT 5"); $htmlCon = ""; if ($r->num_rows > 0) { $s_data = []; while ($rs = $r->fetch_assoc()) { $s_data[] = $rs; } $getLastId = array_reverse($s_data); $section_lastid = $getLastId[0]['section_position_id']; foreach ($s_data as $s_d) { $s_title = htmlspecialchars(stripslashes($s_d['title'])); $s_id = $s_d['id']; ob_start(); echo '<div class="cfcourse-s-c cfcourse-s-c-short ui-state-default" > <div class="cfcourse-s p-1 px-sm-2 py-2 cf--c--srtab" id="cfcourse-s-' . $s_id . '" data-sid="' . $s_id . '"> <div class="cfcource-section cf--c--srtab" tabindex="-1" > <div class="cfcourse-section-c cf--c--srtab"> <div class="d-flex cf--c--srtab justify-content-between justify-content-md-between align-items-center my-1 my-sm-0 flex-column flex-sm-row"> <div style="cursor: initial;" class="cf--course-stitle"> <span style="font-weight:bold" >' . t('Section') . '. <span class="cfcourse-s-count"></span>: </span> <span class="cfcourse-s-t-t " > ' . ((strlen($s_title) > 120) ? substr($s_title, 0, 120) . '...' : $s_title) . ' <span> </div> <div style="cursor: initial;" class="cfcourse-s-action cfcourse-s-action pt-2 pt-sm-0 p-sm-0 "> <div class="d-flex"> <div class="p-1 cfcourse-open-s-btn" data-bs-toggle="collapse" data-bs-target="#cf-course-secop-' . $s_id . '"><button class="cfcourse-open-s-btn btn btn-primary d-inline-block" id="" title="' . t('Open Section') . '"> <i class="fas fa-angle-down cfcourse-s-d-arr d-inline-block cfcourse-open-s-btn" ></i></button></div> <div class="p-1 cfcourse-edit-s-btn"> <button class=" cfcourse-edit-s-btn btn btn-success d-inline-block" title="' . t('Edit Section') . '"> <i class="fas fa-edit d-inline-block cfcourse-edit-s-btn"></i> </button></div> <div class="p-1 cfcourse-del-s-btn cfcourse-del-s" data-s-id="' . $s_id . '"><button class=" cfcourse-del-s-btn btn btn-danger" title="' . t('Delete Section') . '"> <i class="fas fa-trash cfcourse-del-s-btn"></i> </button></div> </div> </div> </div> </div> <div class="cfcourse-update-s-d"> <div class="cfcourse-s-d "> <form action="" class="cfcourse-add-section" method="" autocomplete="off"> <input type="hidden" name="cfcourse_section_action" value="update_section" /> <input type="hidden" name="cfcourse_section_id" value="' . $s_id . '" /> <input type="hidden" name="cfcourse_course_id" value="' . $course_id . '" /> <p class="p-1 text-primary text-center font-weight-bold">' . t('Update Section') . ' </p> <div class="mb-3 mb-1 "> <label class="text-primary font-weight-bold" >' . t('Title') . '*</label> <div class="cfcourse-a-s-i justify-content-center flex-sm-row flex-column d-flex"> <input type="text" placeholder="' . t('Title') . '" value="' . $s_title . '" name="cfcourse_seciton" class="flex-2 form-control cf-course-sec-edit cfcourse_a_t_i" /> </div> </div> <div class="cfcourse-title-e"> </div> <div class="text-center mt-3 d-flex justify-content-center"> <div class="mx-1"> <button type="button" class="btn btn-danger cfcourse-cancel-s-btn">' . t('Cancel') . '</button> </div> <div class="mx-1"> <button type="submit" class="btn btn-primary">' . t('Save Changes') . '</button> </div> </div> </form> </div> </div> </div> <div class="cfcourse-options-f-c collapse" id="cf-course-secop-' . $s_id . '"> <div class="cfcourse-o-a-o cfcourse-a-a-t text-center mt-4" data-c-id="' . $course_id . '" data-s-id="' . $s_id . '"> <div class="cfcourse-a-o-c cfcourse-a-o"> <div class="cfcourse-a-o"><button class="btn btn-primary cfcourse-a-o cfcourse-a-o-btn" title="' . t('Add Content') . '"><span class="cfcourse-a-o cfcourse-a-o-text">+</span></button></div> </div> </div> <div class="cfcourse-options-c pt-1 pt-sm-3 cfcourse-options-sortable px-1 px-sm-5">'; $c_data = $content->getContentData($course_id, $s_id); if (count($c_data) > 0) { foreach ($c_data as $c_d) { $type = $c_d['option_type']; if ($type == "lecture") { echo '<div class="ui-state-default cfcourse-options-i-c" tabindex="-1">'; echo $content->getLectureHtml($c_d, 1); echo '</div>'; } else if ($type == "quiz") { echo '<div class="ui-state-default cfcourse-options-i-c" tabindex="-1" >'; echo $quiz->getQuizHtml($c_d, 1); echo '</div>'; } else if ($type == "assign") { echo '<div class="ui-state-default cfcourse-options-i-c" tabindex="-1">'; echo $assign->getAssignHtml($c_d, 1); echo '</div>'; } else if ($type == "test") { echo '<div class="ui-state-default cfcourse-options-i-c" tabindex="-1">'; echo $assign->getAssignHtml($c_d, 1); echo '</div>'; } } } echo '</div> </div> </div> <div class="cfcourse-add-section-c add-section-bottom text-center mt-1" data-c-id="' . $course_id . '"> <div class="cfcourse-a-s-c p-1 cfcourse-o-a-s add-section-bottom" title="' . t('Add Section') . '"> <button class="btn btn-primary cfcourse-o-a-s">+</button> </div> </div> </div>'; $htmlCon .= ob_get_clean(); } echo json_encode(array("status" => 1, "lastid" => $section_lastid, "data" => $htmlCon)); die(); } else { echo json_encode(array("status" => 0)); die(); } } // It will add a section for course } //class ends }//if exist class ends