Esempio n. 1
0
function tab1($program, $author, $program_content, $exercise, $requirements, $course, $config, $course_config, $device)
{
    $prev_id = 0;
    $diff_start = "";
    $diff_date = "";
    $start_date = "";
    $itemid = "";
    $action = "";
    $lesson_width = "";
    $lesson_height = "";
    $st_psgpage = json_decode($config->st_psgpage);
    $psgpage = json_decode($config->psgpage);
    $course_level = $psgpage->course_level;
    $buy_class = $st_psgpage->course_other_button;
    $buy_background = $st_psgpage->course_other_background;
    $my = JFactory::getUser();
    $course_id = intval(JRequest::getVar("cid", 0));
    $show_buy_button = $course_config->course_buy_button;
    $buy_button_location = $course_config->course_buy_button_location;
    $user_id = $my->id;
    @($user->id = $my->id);
    $lesson_size = $config->lesson_window_size;
    $lesson_size = explode("x", $lesson_size);
    $lesson_height = $lesson_size["0"];
    $lesson_width = $lesson_size["1"];
    $style_grayout = "color:#999999;";
    $db = JFactory::getDBO();
    $sql = "select name, alias from #__guru_program where id=" . intval($course_id);
    $db->setQuery($sql);
    $db->query();
    $result = $db->loadAssocList();
    $alias = $result["0"]["alias"] == "" ? JFilterOutput::stringURLSafe($result["0"]["name"]) : $result["0"]["alias"];
    $sql = "SELECT  count(*) FROM `#__guru_buy_courses` where `order_id` >='0' and `userid`=" . intval($user_id) . " and course_id=" . intval($course_id);
    $db->setQuery($sql);
    $db->query();
    $result = $db->loadResult();
    if ($result > 0) {
        $not_show = true;
    } else {
        $not_show = false;
    }
    $sql = "SELECT chb_free_courses, step_access_courses, selected_course  FROM `#__guru_program` where id = " . intval($course_id);
    $db->setQuery($sql);
    $db->query();
    $result = $db->loadAssocList();
    $chb_free_courses = $result["0"]["chb_free_courses"];
    $step_access_courses = $result["0"]["step_access_courses"];
    $selected_course = $result["0"]["selected_course"];
    $hascourse = false;
    if (buySelectedCourse($selected_course)) {
        $hascourse = true;
    }
    $coursetype_details = guruModelguruProgram::getCourseTypeDetails($course_id);
    if ($course_level == 1) {
        $display_levelimg = "none";
    } else {
        $display_levelimg = "inherit-inline";
    }
    $detect = new Mobile_Detect();
    $deviceType = $detect->isMobile() ? $detect->isTablet() ? 'tablet' : 'phone' : 'computer';
    $authors = $program->author;
    $authors = explode("|", $authors);
    $authors = array_filter($authors);
    $itemid = JRequest::getVar("Itemid", "0");
    ?>
    
<div><!-- start main div-->
    <div class="table-of-contents">
            <?php 
    if ($show_buy_button == "0" && ($buy_button_location == "0" || $buy_button_location == "2")) {
        ?>
        <div class="uk-alert uk-hidden-small hidden-phone">
		   <?php 
        $button = createButton($buy_background, $course_id, $buy_class, $program, $program_content);
        // display message like "Get access to all the tutorials in the course now! and Buy Now button"
        if (is_array($button)) {
            echo $button["0"];
        } else {
            echo $button;
        }
        ?>
        </div>
            <?php 
    }
    ?>
    <div class="uk-grid">
            <?php 
    $show_all_cloase_all = isset($course_config->show_all_cloase_all) ? $course_config->show_all_cloase_all : "0";
    if ($user_id > 0) {
        $col_width = 9;
    } else {
        $col_width = 8;
    }
    $model = new guruModelguruProgram();
    $expired_license = $model->getExpiredLicense($program);
    if ($user_id > 0 && $coursetype_details[0]["course_type"] != 0 && $coursetype_details[0]["lessons_show"] == 1 && $coursetype_details[0]["lesson_release"] > 0 && $not_show === TRUE && !in_array($user_id, $authors) && !$expired_license) {
        $col_width = 7;
    }
    if (isset($course_config->duration) && $course_config->duration == 0) {
        $col_width = $col_width - 2;
    }
    if (isset($course_config->quiz_status) && $course_config->quiz_status == 0) {
        $col_width = $col_width - 2;
    }
    ?>
            <div class="col_title uk-width-large-1-2 uk-width-medium-1-2 uk-width-small-1-1">
				<?php 
    if ($show_all_cloase_all != 1) {
        ?>
                        <input type="button" class="uk-button uk-button-primary show_sub" value="+ <?php 
        echo JText::_("GURU_SHOW_ALL_BUTTON");
        ?>
"/><!--show all button -->
                        <input type="button" class="uk-button uk-button-primary close_sub" value="- <?php 
        echo JText::_("GURU_CLOSE_ALL_BUTTON");
        ?>
"/><!--close all button -->
                    <?php 
    } else {
        echo '&nbsp;';
    }
    ?>
			</div>
            
			<div class="uk-width-1-2 uk-hidden-small hidden-phone">
				<?php 
    $nr_columns = 1;
    if (isset($course_config->duration) && $course_config->duration == 0) {
        $nr_columns++;
    }
    if (isset($course_config->quiz_status) && $course_config->quiz_status == 0) {
        $nr_columns++;
    }
    if ($course_level == 0) {
        $nr_columns++;
    }
    if ($user_id > 0 && $coursetype_details[0]["course_type"] != 0 && $coursetype_details[0]["lessons_show"] == 1 && $coursetype_details[0]["lesson_release"] > 0 && $not_show === TRUE && !in_array($user_id, $authors) && !$expired_license) {
        $nr_columns++;
    }
    ?>
                
                <?php 
    if (isset($course_config->quiz_status) && $course_config->quiz_status == 0 && $device == "d") {
        ?>
                        <div class="col_title pull-left uk-width-1-<?php 
        echo intval($nr_columns);
        ?>
 uk-text-right">
                            <?php 
        echo JText::_("GURU_QUIZ_STATUS");
        ?>
                        </div>
                <?php 
    }
    ?>
                
                <div class="col_title pull-left uk-width-1-<?php 
    echo intval($nr_columns);
    ?>
 uk-text-right">
                    <?php 
    echo JText::_("GURU_VIEWED");
    ?>
                </div>
            
				<?php 
    if (isset($course_config->duration) && $course_config->duration == 0 && $device == "d") {
        ?>
                        <div class="col_title pull-left uk-width-1-<?php 
        echo intval($nr_columns);
        ?>
 uk-text-right">
                            <?php 
        echo JText::_("GURU_DURATION");
        ?>
                            <br />
                            <span id="total-duration-2"></span>
                        </div>
                <?php 
    }
    ?>

            
                <div class="col_title pull-left uk-width-1-<?php 
    echo intval($nr_columns);
    ?>
 uk-text-right">
                        <?php 
    if ($course_level == 0) {
        echo JText::_("GURU_LEVEL");
    }
    ?>
<!--Level -->
                </div>
				<?php 
    if ($user_id > 0 && $coursetype_details[0]["course_type"] != 0 && $coursetype_details[0]["lessons_show"] == 1 && $coursetype_details[0]["lesson_release"] > 0 && $not_show === TRUE && !in_array($user_id, $authors) && !$expired_license) {
        ?>
                    <div class="col_title pull-left uk-width-1-<?php 
        echo intval($nr_columns);
        ?>
 uk-text-right">
                        <?php 
        echo JText::_("GURU_AVAILABILITY");
        ?>
                    </div>
                    <?php 
    }
    ?>
			</div>
    </div>
    
        <?php 
    // start calculation for one lesson per (option in admin)
    if ($user_id > 0) {
        $db = JFactory::getDBO();
        $sql = "select DATE_FORMAT(buy_date,'%Y-%m-%d %H:%i:%s') from #__guru_buy_courses where course_id=" . intval($course_id) . " and userid =" . $user_id;
        $db->setQuery($sql);
        $db->query();
        $date_enrolled = $db->loadResult();
        $date_enrolled = strtotime($date_enrolled);
    }
    if (isset($date_enrolled) && $date_enrolled !== FALSE && !is_null($date_enrolled)) {
        $start_relaese_date1 = $coursetype_details[0]["start_release"];
        $start_relaese_date = strtotime($start_relaese_date1);
        $start_date = $date_enrolled;
        $jnow = JFactory::getDate();
        $date9 = $jnow->toSQL();
        $date_9 = date("Y-m-d", strtotime($date9));
        $date9 = strtotime($date9);
        $interval = abs($date9 - $start_date);
        $dif_days = floor($interval / (60 * 60 * 24));
        $dif_week = floor($interval / (60 * 60 * 24 * 7));
        $dif_month = floor($interval / (60 * 60 * 24 * 30));
        if ($coursetype_details[0]["course_type"] == 1) {
            if ($coursetype_details[0]["lesson_release"] == 1) {
                $diff_start = $dif_days + 1;
                $diff_date = $dif_days + 1;
            } elseif ($coursetype_details[0]["lesson_release"] == 2) {
                $diff_start = $dif_week + 1;
                $diff_date = $dif_week + 1;
            } elseif ($coursetype_details[0]["lesson_release"] == 3) {
                $diff_start = $dif_month + 1;
                $diff_date = $dif_month + 1;
            }
        }
    }
    $guruModelguruTask = new guruModelguruTask();
    $step_less = @$diff_start;
    $guruModelguruProgram = new guruModelguruProgram();
    $total_hours = 0;
    $total_minutes = 0;
    $total_seconds = 0;
    foreach ($program_content as $key => $module) {
        $lessons = $guruModelguruProgram->getSubCategory($module['id']);
        ?>
        	<div class="chapter_wrap t_row">
            	<div>
                	<div>
                    	<!-- start module -->
                        <div class="chapter_title clearfix">
							<div>
								<div class="day clearfix" onClick="javascript:show_hidde('<?php 
        echo $module['id'];
        ?>
','<?php 
        echo JUri::root() . "components/com_guru/images/";
        ?>
')">
                                	<img id='img_<?php 
        echo $device . "_" . $module['id'];
        ?>
' src='<?php 
        echo JUri::root() . "components/com_guru/images/arrow-right.gif";
        ?>
' />
                            		<?php 
        echo $module['title'];
        ?>
                        		</div>
                    		</div>
                		</div>
                        <!-- stop module -->
                        <?php 
        // start lessons
        $lesson_details_for_quiz = array();
        if (isset($lessons) && count($lessons) > 0) {
            ?>
                        		<div class="lessons_wrap">                          
                                	<div id='td_<?php 
            echo $device . "_" . $module['id'];
            ?>
'>
                                    	<div id='table_<?php 
            echo $device . "_" . $module['id'];
            ?>
' class="subcat">
                                        	<ul>
												<?php 
            $model = new guruModelguruProgram();
            foreach ($lessons as $poz => $lesson) {
                $nr_columns = 2;
                if ($course_level == 0) {
                    // show level icon
                    $nr_columns = 3;
                }
                $lesson = $model->checkLessonQuiz($lesson, $program);
                $lesson_details_for_quiz[] = $lesson;
                $lesson = $model->getLessonDetails($program, $author, $lesson, $diff_date, $diff_start, $step_less, $start_date, $config, $lesson_details_for_quiz, $poz);
                if (isset($lesson["not_show_lesson"]) && trim($lesson["not_show_lesson"]) == "1") {
                    continue;
                }
                $minutes = 0;
                $seconds = 0;
                if (isset($lesson['duration']) && trim($lesson['duration']) != "") {
                    $temp_duration = explode("x", trim($lesson['duration']));
                    $total_minutes += $temp_duration["0"];
                    $total_seconds += $temp_duration["1"];
                    $minutes = $temp_duration["0"];
                    $seconds = $temp_duration["1"];
                }
                $imgLevel = "";
                switch ($lesson['difficultylevel']) {
                    case "easy":
                        $imgLevel = "beginner_level.png";
                        break;
                    case "medium":
                        $imgLevel = "intermediate_level.png";
                        break;
                    case "hard":
                        $imgLevel = "advanced_level.png";
                        break;
                }
                $link = "";
                $onclick = "";
                $lesson_span = "span9";
                $available_date = "";
                $style = "";
                $inactive_lesson_class = "";
                if ($lesson["can_open_lesson"] == "1") {
                    // access to this lesson
                    if ($config->open_target == 0) {
                        // same window
                        $link = "index.php?option=com_guru&view=gurutasks&catid=" . $program->catid . "&module=" . $module["id"] . "-" . $module["alias"] . "&cid=" . $lesson['id'] . "-" . $lesson["alias"] . "&Itemid=" . $itemid;
                        $onclick = "javascript:setViewed('viewed-" . $lesson['id'] . "', '" . JURI::root() . "components/com_guru/images/icons/viewed.gif')";
                    } elseif ($config->open_target == 1) {
                        // modal window
                        $link = "#";
                        $onclick = "openMyModal('0', '0', '" . JURI::root() . "index.php?option=com_guru&view=gurutasks&catid=" . $program->catid . "&module=" . $module["id"] . "-" . $module["alias"] . "&cid=" . $lesson['id'] . "-" . $lesson["alias"] . "&tmpl=component&Itemid=" . $itemid . "'); return false; javascript:setViewed('viewed-" . $lesson['id'] . "', '" . JURI::root() . "components/com_guru/images/icons/viewed.gif" . "')";
                    }
                    if (isset($course_config->duration) && $course_config->duration == 0) {
                        $nr_columns++;
                    }
                    if (isset($course_config->quiz_status) && $course_config->quiz_status == 0) {
                        $nr_columns++;
                    }
                    if (isset($lesson["available_div"]) && trim($lesson["available_div"]) != "") {
                        // add AVAILABLE language var
                        $available_date = trim($lesson["available_div"]);
                        $nr_columns++;
                    }
                } elseif ($lesson["can_open_lesson"] == "0") {
                    // no access to this lesson
                    $inactive_lesson_class = "inactive-lesson";
                    if (isset($lesson["finish_required_courses"]) && $lesson["finish_required_courses"] == 1) {
                        // start open alert modal with required courses message
                        $link = "#";
                        $onclick = "openMyModal('0','0','" . JURI::root() . "index.php?option=com_guru&view=guruProfile&task=required_courses_message&graybox=true&tmpl=component'); return false;";
                        // stop open alert modal with required courses message
                    } elseif (isset($lesson["lesson_quiz_student_go_on"]) && $lesson["lesson_quiz_student_go_on"] == '0') {
                        // start exist quizzes that are not completed
                        $link = "#";
                        $onclick = "alert('" . JText::_("GURU_NO_FINISHED_QUIZZES_BEFORE_LESSON") . "')";
                        // stop exist quizzes that are not completed
                    } elseif (isset($lesson["enroll_to_course"]) && $lesson["enroll_to_course"] == 1) {
                        // start open enroll modal
                        $link = "#";
                        $onclick = "openMyModal('0','0','" . JURI::root() . "index.php?option=com_guru&view=guruProfile&task=loginform&course_id=" . intval($course_id) . "-" . $alias . $action . "&returnpage=guruprograms&graybox=true&tmpl=component'); return false;";
                        // stop open enroll modal
                    } elseif (isset($lesson["available_div"]) && trim($lesson["available_div"]) != "") {
                        // do nothing, the lesson is not available
                        $link = "#";
                        $onclick = "return false";
                        $available_date = trim($lesson["available_div"]);
                        $style = "style='color:#999999;'";
                        $step_less++;
                        $nr_columns++;
                    } elseif (isset($lesson["need_enroll"]) && $lesson["need_enroll"] == "1") {
                        $link = "#";
                        $onclick = "openMyModal('0', '0', '" . JURI::root() . "index.php?option=com_guru&view=guruProfile&task=loginform&course_id=" . $program->id . "&tmpl=component&Itemid=" . $itemid . "'); return false;";
                    } elseif (isset($lesson["need_registration"]) && $lesson["need_registration"] == "1") {
                        $link = "index.php?option=com_guru&view=guruLogin&Itemid=" . $itemid;
                        $onclick = "";
                    } else {
                        if (isset($lesson["available_div"]) && trim($lesson["available_div"]) != "") {
                            // add AVAILABLE language var
                            $nr_columns++;
                            $available_date = trim($lesson["available_div"]);
                        }
                        // start open course plans for buy
                        $itemid = JRequest::getVar("Itemid", "0");
                        $link = "#";
                        $onclick = "openMyModal('0','0','" . JURI::root() . "index.php?option=com_guru&view=guruEditplans&course_id=" . intval($course_id) . "-" . $alias . @$action . "&tmpl=component&Itemid=" . intval($itemid) . "'); return false;";
                        // stop open course plans for buy
                    }
                    if (isset($course_config->duration) && $course_config->duration == 0) {
                        $nr_columns++;
                    }
                    if (isset($course_config->quiz_status) && $course_config->quiz_status == 0) {
                        $nr_columns++;
                    }
                }
                if (isset($config->indicate_quiz) && intval($config->indicate_quiz) == 1) {
                    $count = $guruModelguruProgram->getCount($module["id"], $lesson['id']);
                    if ($count > 0) {
                        $lesson['name'] .= ' [' . JText::_("GURU_QUIZ") . ']';
                    }
                }
                if ($diff_date != "") {
                    @$diff_date--;
                }
                ?>
                                                		<li class="uk-grid" <?php 
                echo $style;
                ?>
>
															<div class="uk-width-1-2 lesson_name">
                                                                <a onclick="<?php 
                echo $onclick;
                ?>
" href="<?php 
                echo $link;
                ?>
" <?php 
                echo $style;
                ?>
 class="<?php 
                echo $inactive_lesson_class;
                ?>
">
                                                                    <?php 
                echo $lesson['name'];
                ?>
                                                                </a>
                                                        	</div>
                                                            <?php 
                $user_id = $my->id;
                $display = "hidden";
                if ($user_id > 0) {
                    $lesson_viewed = $guruModelguruTask->getViewLesson($lesson['id']);
                    if (isset($lesson_viewed) && $lesson_viewed === TRUE) {
                        $display = "inherit";
                    }
                }
                ?>
                                                            <div class="uk-width-1-2">
                                                            	<?php 
                if (isset($course_config->quiz_status) && $course_config->quiz_status == 0) {
                    ?>
                                                            		<div class="uk-width-1-<?php 
                    echo $nr_columns - 1;
                    ?>
 pull-left uk-text-right">
                                                                        <?php 
                    if (isset($lesson["quiz_passed"]) && $lesson["quiz_passed"] == -1) {
                        // pending
                        echo '<span class="lesson-quizz-pending">' . JText::_("GURU_PENDING") . '</span>';
                    } elseif (isset($lesson["quiz_passed"]) && $lesson["quiz_passed"] == 0) {
                        // failed
                        echo '<span class="lesson-quizz-failed">' . JText::_("GURU_QUIZ_FAILED_STATUS") . '</span>';
                    } elseif (isset($lesson["quiz_passed"]) && $lesson["quiz_passed"] == 1) {
                        // passed
                        echo '<span class="lesson-quizz-passed">' . JText::_("GURU_QUIZ_PASSED_STATUS") . '</span>';
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                                                                    </div>
                                                            <?php 
                }
                ?>
                                                            
                                                                <div style="visibility:<?php 
                echo $display;
                ?>
;" class="uk-width-1-<?php 
                echo $nr_columns - 1;
                ?>
 viewed pull-left uk-text-right">
                                                                    <i class="fa fa-eye"></i>
                                                                </div>
                                                            
                                                            <?php 
                if (isset($course_config->duration) && $course_config->duration == 0) {
                    ?>
                                                            		<div class="uk-width-1-<?php 
                    echo $nr_columns - 1;
                    ?>
 pull-left uk-text-right">
                                                                        <?php 
                    if (intval($minutes) != 0) {
                        echo intval($minutes) . "m ";
                    }
                    if (intval($seconds) != 0) {
                        echo intval($seconds) . "s ";
                    }
                    if (intval($minutes) == 0 && intval($seconds) == 0) {
                        echo '&nbsp;';
                    }
                    ?>
                                                                    </div>
                                                            <?php 
                }
                ?>
                                                            
                                                                <div class="uk-width-1-<?php 
                echo $nr_columns - 1;
                ?>
 pull-left uk-text-right">
                                                                <?php 
                if ($course_level == 0) {
                    // show course level
                    ?>
                                                                        <img style="background-color:transparent;" src="<?php 
                    echo JURI::root() . "components/com_guru/images/" . $imgLevel;
                    ?>
" />
                                                                <?php 
                }
                ?>
                                                                </div>
                                                                <?php 
                $available_date = str_replace("replace_class", 'uk-width-1-' . ($nr_columns - 1) . ' uk-text-right', $available_date);
                echo $available_date;
                ?>
															</div>
														</li>
                                                <?php 
            }
            ?>
                                            </ul>
										</div>
									</div>
								</div>
                        <?php 
        }
        // stop lessons
        ?>
                    </div>
                </div>
            </div>
		<?php 
    }
    $total_minutes += floor($total_seconds / 60);
    $total_seconds = $total_seconds % 60;
    if (intval($total_minutes) >= 60) {
        $total_hours = floor($total_minutes / 60);
        $total_minutes = $total_minutes % 60;
    }
    $display_duration_1 = array();
    $display_duration_2 = array();
    if (intval($total_hours) > 0) {
        if (intval($total_hours) > 1) {
            $display_duration_1[] = $total_hours . " " . JText::_("GURU_PROGRAM_DETAILS_HOURS");
        } else {
            $display_duration_1[] = $total_hours . " " . JText::_("GURU_PROGRAM_DETAILS_HOUR");
        }
        $display_duration_2[] = $total_hours . "h";
    }
    if (intval($total_minutes) > 0) {
        if (intval($total_minutes) > 1) {
            $display_duration_1[] = $total_minutes . " " . JText::_("GURU_PROGRAM_DETAILS_MINUTES");
        } else {
            $display_duration_1[] = $total_minutes . " " . JText::_("GURU_PROGRAM_DETAILS_MINUTE");
        }
        $display_duration_2[] = $total_minutes . "m";
    }
    if (intval($total_seconds) > 0) {
        if (intval($total_minutes) > 1) {
            $display_duration_1[] = $total_seconds . " " . JText::_("GURU_PROGRAM_DETAILS_SECONDS");
        } else {
            $display_duration_1[] = $total_seconds . " " . JText::_("GURU_PROGRAM_DETAILS_SECOND");
        }
        $display_duration_2[] = $total_seconds . "s";
    }
    if (isset($course_config->duration) && $course_config->duration == 0) {
        ?>
			<script type="text/javascript" language="javascript">
				document.getElementById("total-duration-1").innerHTML = "<?php 
        echo implode(", ", $display_duration_1);
        ?>
";
				document.getElementById("total-duration-2").innerHTML = "<?php 
        echo implode(" ", $display_duration_2);
        ?>
";
			</script>
		<?php 
    }
    if ($show_buy_button == "0" && ($buy_button_location == "1" || $buy_button_location == "2")) {
        $button = createButton($buy_background, $course_id, $buy_class, $program, $program_content);
        if (!is_array($button)) {
            ?>
            <div class="uk-alert">
				<?php 
            if (!is_array($button)) {
                echo $button;
            }
            ?>
            </div>
                <?php 
        }
    }
    ?>
        </div>
</div><!-- end main div-->
    <?php 
}