function JLMS_saveLink($option)
{
    global $my, $JLMS_DB, $Itemid, $JLMS_CONFIG;
    $JLMS_ACL =& JLMSFactory::getACL();
    $course_id = $JLMS_CONFIG->get('course_id');
    $id = intval(mosGetParam($_REQUEST, 'id', 0));
    if ($JLMS_ACL->CheckPermissions('links', 'manage') && ($id && JLMS_GetLinkCourse($id) == $course_id || !$id)) {
        $row = new mos_Joomla_LMS_Link($JLMS_DB);
        if (!$row->bind($_POST)) {
            echo "<script> alert('" . addslashes($row->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $params = '';
        $params_p = mosGetParam($_POST, 'params', '');
        if (is_array($params_p)) {
            $txt = array();
            foreach ($params_p as $k => $v) {
                $txt[] = "{$k}={$v}";
            }
            $params = implode("\n", $txt);
        }
        $row->params = $params;
        //$row->link_name = strval(mosGetParam($_POST, 'link_name', ''));
        $row->link_href = strval(mosGetParam($_POST, 'link_href', ''));
        $days = intval(mosGetParam($_POST, 'days', ''));
        $hours = intval(mosGetParam($_POST, 'hours', ''));
        $mins = intval(mosGetParam($_POST, 'mins', ''));
        if ($row->is_time_related) {
            $row->show_period = JLMS_HTML::_('showperiod.getminsvalue', $days, $hours, $mins);
        }
        if (!$id) {
            $row->owner_id = $my->id;
        } else {
            unset($row->owner_id);
            if ($JLMS_ACL->CheckPermissions('links', 'only_own_items') && JLMS_GetLinkOwner($id) != $my->id) {
                JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=links&id={$course_id}"));
            } elseif ($JLMS_ACL->CheckPermissions('links', 'only_own_role') && $JLMS_ACL->GetRole() != $JLMS_ACL->UserSystemRole($JLMS_DB, JLMS_GetLinkOwner($id))) {
                JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=links&id={$course_id}"));
            }
        }
        $row->link_name = strval(JLMS_getParam_LowFilter($_POST, 'link_name', ''));
        $row->link_name = JLMS_Process_ContentNames($row->link_name);
        // 26.02.2007 (Media content integration)
        $row->link_description = strval(JLMS_getParam_LowFilter($_POST, 'link_description', ''));
        $row->link_description = JLMS_ProcessText_LowFilter($row->link_description);
        //$iFilter = new JLMS_InputFilter(null,null,1,1);
        //$row->link_description = $iFilter->process( $row->link_description );
        $row->link_type = intval(mosGetParam($_REQUEST, 'link_type', 0));
        if (!$JLMS_ACL->CheckPermissions('links', 'publish')) {
            $row->published = 0;
        }
        if (!$JLMS_ACL->CheckPermissions('links', 'order')) {
            $row->ordering = 0;
        }
        if (!$row->check()) {
            echo "<script> alert('" . addslashes($row->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$row->store()) {
            echo "<script> alert('" . addslashes($row->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=links&id={$course_id}"));
}
 function JQ_saveQuiz($option, $page, $course_id)
 {
     global $JLMS_DB, $my, $Itemid, $JLMS_CONFIG;
     $row = new mos_JoomQuiz_Quiz($JLMS_DB);
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $JLMS_ACL =& JLMSFactory::getACL();
     if (!$JLMS_ACL->CheckPermissions('quizzes', 'publish')) {
         unset($row->published);
     }
     $row->course_id = $course_id;
     $row->c_user_id = $my->id;
     $row->c_skin = 3;
     $row->c_language = 1;
     $row->c_guest = 0;
     $params = mosGetParam($_POST, 'params', '');
     $quiz_params = '';
     if (is_array($params)) {
         $txt = array();
         foreach ($params as $k => $v) {
             $txt[] = "{$k}={$v}";
         }
         $quiz_params = implode("\n", $txt);
     }
     $row->params = $quiz_params;
     if (!$row->c_id) {
         $date = time();
         $s_day = mktime(0, 0, 0, date('m', $date), date('d', $date), date('Y', $date));
         $row->c_created_time = date('Y-m-d', $s_day);
     } else {
         unset($row->c_created_time);
     }
     $row->c_title = strval(JLMS_getParam_LowFilter($_POST, 'c_title', ''));
     $row->c_title = JLMS_Process_ContentNames($row->c_title);
     $row->c_description = strval(JLMS_getParam_LowFilter($_POST, 'c_description', ''));
     $row->c_description = JLMS_ProcessText_LowFilter($row->c_description);
     $row->c_right_message = strval(JLMS_getParam_LowFilter($_POST, 'c_right_message', ''));
     $row->c_right_message = JLMS_ProcessText_LowFilter($row->c_right_message);
     $row->c_wrong_message = strval(JLMS_getParam_LowFilter($_POST, 'c_wrong_message', ''));
     $row->c_wrong_message = JLMS_ProcessText_LowFilter($row->c_wrong_message);
     $row->c_pass_message = strval(JLMS_getParam_LowFilter($_POST, 'c_pass_message', ''));
     $row->c_pass_message = JLMS_ProcessText_LowFilter($row->c_pass_message);
     $row->c_unpass_message = strval(JLMS_getParam_LowFilter($_POST, 'c_unpass_message', ''));
     $row->c_unpass_message = JLMS_ProcessText_LowFilter($row->c_unpass_message);
     $days = intval(mosGetParam($_POST, 'days', ''));
     $hours = intval(mosGetParam($_POST, 'hours', ''));
     $mins = intval(mosGetParam($_POST, 'mins', ''));
     if ($row->is_time_related) {
         $row->show_period = JLMS_HTML::_('showperiod.getminsvalue', $days, $hours, $mins);
     }
     if (!$row->check()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $query = "DELETE FROM #__lms_quiz_t_quiz_pool WHERE quiz_id = {$row->c_id}";
     $JLMS_DB->SetQuery($query);
     $JLMS_DB->query();
     $pool_type = intval(mosGetParam($_REQUEST, 'c_pool_type', 0));
     if ($pool_type == 1) {
         $pool_num = intval(mosGetParam($_REQUEST, 'pool_qtype_number', 0));
         if ($pool_num) {
             $query = "INSERT INTO #__lms_quiz_t_quiz_pool (quiz_id, qcat_id, items_number)" . "\n VALUES({$row->c_id}, 0, {$pool_num})";
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
         }
     } elseif ($pool_type == 2) {
         if (!empty($_REQUEST['pool_cat_id'])) {
             for ($i = 0, $n = count($_REQUEST['pool_cat_id']); $i < $n; $i++) {
                 $row_cid = isset($_REQUEST['pool_cat_id'][$i]) ? intval($_REQUEST['pool_cat_id'][$i]) : 0;
                 $row_num = isset($_REQUEST['pool_cat_number'][$i]) ? intval($_REQUEST['pool_cat_number'][$i]) : 0;
                 if ($row_cid && $row_num) {
                     $query = "SELECT c_id FROM #__lms_quiz_t_category WHERE course_id = {$course_id} AND is_quiz_cat = 0 AND c_id = {$row_cid}";
                     $JLMS_DB->SetQuery($query);
                     $row_check = $JLMS_DB->LoadResult();
                     if ($row_check == $row_cid) {
                         $query = "INSERT INTO #__lms_quiz_t_quiz_pool (quiz_id, qcat_id, items_number)" . "\n VALUES({$row->c_id}, {$row_cid}, {$row_num})";
                         $JLMS_DB->SetQuery($query);
                         $JLMS_DB->query();
                     }
                 }
             }
         }
     }
     if ($JLMS_CONFIG->get('global_quest_pool')) {
         $query = "DELETE FROM #__lms_quiz_t_quiz_gqp WHERE quiz_id = {$row->c_id}";
         $JLMS_DB->SetQuery($query);
         $JLMS_DB->query();
         $pool_type = intval(mosGetParam($_REQUEST, 'c_pool_type_gqp', 0));
         if ($pool_type == 1) {
             $pool_num = intval(mosGetParam($_REQUEST, 'pool_qtype_number_gqp', 0));
             if ($pool_num) {
                 $query = "INSERT INTO #__lms_quiz_t_quiz_gqp (quiz_id, qcat_id, items_number)" . "\n VALUES({$row->c_id}, 0, {$pool_num})";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
             }
         } elseif ($pool_type == 2) {
             if (!empty($_REQUEST['cat_id_gqp'])) {
                 $order = 1;
                 foreach ($_REQUEST['cat_id_gqp'] as $k => $v) {
                     $row_cid = isset($_REQUEST['cat_id_gqp'][$k]) ? intval($_REQUEST['cat_id_gqp'][$k]) : 0;
                     $row_num = isset($_REQUEST['pool_cat_number_gqp'][$k]) ? intval($_REQUEST['pool_cat_number_gqp'][$k]) : 0;
                     if ($row_cid) {
                         //							$query = "SELECT cat_id FROM #__lms_gqp_levels WHERE cat_id = $row_cid";
                         //							$JLMS_DB->SetQuery($query);
                         //							$row_check = $JLMS_DB->LoadResult();
                         //
                         //
                         //							if ($row_check == $row_cid) {
                         $query = "INSERT INTO #__lms_quiz_t_quiz_gqp (quiz_id, qcat_id, items_number, orderin)" . "\n VALUES({$row->c_id}, {$row_cid}, {$row_num}, {$order})";
                         $JLMS_DB->SetQuery($query);
                         $JLMS_DB->query();
                         $order++;
                         //							}
                     }
                 }
                 //				for ($i = 0, $n = count($_REQUEST['cat_id_gqp']); $i < $n; $i ++) {
                 //					$row_cid = isset($_REQUEST['cat_id_gqp'][$i]) ? intval($_REQUEST['cat_id_gqp'][$i]) : 0;
                 //					$row_num = isset($_REQUEST['pool_cat_number_gqp'][$i]) ? intval($_REQUEST['pool_cat_number_gqp'][$i]) : 0;
                 //					if ($row_cid && $row_num) {
                 //
                 //						$query = "SELECT cat_id FROM #__lms_gqp_levels WHERE cat_id = $row_cid";
                 //						$JLMS_DB->SetQuery($query);
                 //						$row_check = $JLMS_DB->LoadResult();
                 //
                 //						if ($row_check == $row_cid) {
                 //
                 //							$query = "INSERT INTO #__lms_quiz_t_quiz_gqp (quiz_id, qcat_id, items_number)"
                 //							. "\n VALUES($row->c_id, $row_cid, $row_num)";
                 //							$JLMS_DB->SetQuery($query);
                 //							$JLMS_DB->query();
                 //
                 //						}
                 //					}
                 //				}
             }
         }
     }
     if ($page == 'apply_quiz') {
         JLMSRedirect($JLMS_CONFIG->get('live_site') . "/index.php?option={$option}&Itemid={$Itemid}&task=quizzes&id={$course_id}&page=editA_quiz&c_id=" . $row->c_id);
     } else {
         JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&id={$course_id}&page=quizzes"));
     }
 }