function JLMS_deleteDropBox($course_id, $option)
{
    global $my, $JLMS_DB, $Itemid;
    $usertype = JLMS_GetUserType($my->id, $course_id);
    if ($course_id && $usertype == 1) {
        $cid = mosGetParam($_REQUEST, 'cid', array(0));
        if (is_array($cid) && count($cid) > 0) {
            $cids = implode(',', $cid);
            $query = "SELECT distinct file_id FROM #__lms_dropbox WHERE id IN ({$cids}) AND course_id = '" . $course_id . "'";
            $JLMS_DB->SetQuery($query);
            $files = $JLMS_DB->LoadResultArray();
            if (count($files)) {
                $query = "DELETE FROM #__lms_dropbox WHERE id IN ({$cids}) AND course_id = '" . $course_id . "'";
                $JLMS_DB->SetQuery($query);
                $JLMS_DB->query();
                $files_del = JLMS_checkFiles($course_id, $files);
                if (count($files_del)) {
                    JLMS_deleteFiles($files_del);
                }
            }
        }
    } elseif ($course_id && $usertype == 2) {
        $cid = mosGetParam($_REQUEST, 'cid', array(0));
        if (is_array($cid) && count($cid) > 0) {
            $cids = implode(',', $cid);
            $query = "SELECT distinct file_id FROM #__lms_dropbox WHERE id IN ({$cids}) AND course_id = '" . $course_id . "' AND owner_id = '" . $my->id . "'";
            $JLMS_DB->SetQuery($query);
            $files = $JLMS_DB->LoadResultArray();
            if (count($files)) {
                $query = "DELETE FROM #__lms_dropbox WHERE id IN ({$cids}) AND course_id = '" . $course_id . "' AND owner_id = '" . $my->id . "'";
                $JLMS_DB->SetQuery($query);
                $JLMS_DB->query();
                $files_del = JLMS_checkFiles($course_id, $files);
                if (count($files_del)) {
                    JLMS_deleteFiles($files_del);
                }
            }
        }
    }
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}"));
}
Esempio n. 2
0
 function JLMS_saveCertificate($course_id, $option, $crtf_type, $redirect_url = '')
 {
     global $my, $JLMS_DB, $Itemid;
     $JLMS_ACL =& JLMSFactory::getACL();
     $crtf_id = 0;
     /*echo '<pre>';
     	print_r($_REQUEST);*/
     if ($course_id && $JLMS_ACL->CheckPermissions('docs', 'view')) {
         $crtf_name = isset($_REQUEST['crtf_name']) ? $_REQUEST['crtf_name'] : '';
         $crtf_name = get_magic_quotes_gpc() ? stripslashes($crtf_name) : $crtf_name;
         $crtf_name = ampReplace(strip_tags($crtf_name));
         $crtf_name = $JLMS_DB->GetEscaped($crtf_name);
         $crtf_text = isset($_REQUEST['crtf_text']) ? $_REQUEST['crtf_text'] : '';
         $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
         $crtf_text = ampReplace(strip_tags($crtf_text));
         $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
         $crtf_align = intval(mosGetParam($_REQUEST, 'crtf_align', 0));
         $published = intval(mosGetParam($_REQUEST, 'published', 1));
         $crtf_shadow = intval(mosGetParam($_REQUEST, 'crtf_shadow', 0));
         $crtf_font = strval(mosGetParam($_REQUEST, 'crtf_font', 0));
         if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
             $crtf_font = 'arial.ttf';
         }
         if ($crtf_shadow) {
             $crtf_shadow = 1;
         }
         if (!in_array($crtf_align, array(0, 1, 2))) {
             $crtf_align = 0;
         }
         $text_x = intval(mosGetParam($_REQUEST, 'text_x', 0));
         $text_y = intval(mosGetParam($_REQUEST, 'text_y', 0));
         $text_size = intval(mosGetParam($_REQUEST, 'text_size', 0));
         $new_file = false;
         $file_id = 0;
         if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name'])) {
             $file_id = JLMS_uploadFile($course_id);
             $new_file = true;
         }
         $add_query = '';
         $crtf_id = 0;
         if ($crtf_type == 2) {
             $crtf_id = intval(mosGetParam($_REQUEST, 'crtf_id', 0));
             $add_query = " AND id = '" . $crtf_id . "'";
         }
         $query = "SELECT * FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $crtf_type . "' AND parent_id = 0" . $add_query;
         $JLMS_DB->SetQuery($query);
         $old_crt = $JLMS_DB->LoadObjectList();
         if (count($old_crt)) {
             $old_file = $old_crt[0]->file_id;
             if ($old_file && $new_file) {
                 $files = array();
                 $files[] = $old_file;
                 JLMS_deleteFiles($files);
             }
             $crtf_id = $old_crt[0]->id;
             $query = "UPDATE #__lms_certificates SET published = {$published}, crtf_name = '" . $crtf_name . "', crtf_text = '" . $crtf_text . "', crtf_align = {$crtf_align}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . "" . ($new_file ? ", file_id = '" . $file_id . "'" : '') . " WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $crtf_type . "' AND parent_id = 0" . $add_query;
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
         } else {
             $query = "INSERT INTO #__lms_certificates (parent_id, course_id, published, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size" . ($new_file ? ", file_id" : '') . ", crtf_type, crtf_font) VALUES ( 0, '" . $course_id . "', '" . $published . "', '" . $crtf_name . "', '" . $crtf_text . "', {$crtf_align}, {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "'" . ($new_file ? ",'" . $file_id . "'" : '') . ", '" . $crtf_type . "', " . $JLMS_DB->quote($crtf_font) . ")";
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
             $crtf_id = $JLMS_DB->insertid();
         }
         $crtf_id = intval($crtf_id);
         /* 23 october 2007 - (DEN) */
         /* handle custom text fields */
         $ctxt_mes_ids = josGetArrayInts('ctxt_mes_id', $_REQUEST);
         $ctxt_mes_text = isset($_REQUEST['ctxt_mes_text']) ? $_REQUEST['ctxt_mes_text'] : array();
         $ctxt_mes_shadow_hid = mosGetParam($_REQUEST, 'ctxt_mes_shadow_hid', array());
         $ctxt_mes_x = mosGetParam($_REQUEST, 'ctxt_mes_x', array());
         $ctxt_mes_y = mosGetParam($_REQUEST, 'ctxt_mes_y', array());
         $ctxt_mes_h = mosGetParam($_REQUEST, 'ctxt_mes_h', array());
         $ctxt_mes_font = mosGetParam($_REQUEST, 'ctxt_mes_font', array());
         $p_ids = array();
         $i = 0;
         $add_cmes_ids = array();
         /*print_r($ctxt_mes_ids);*/
         foreach ($ctxt_mes_ids as $cmid) {
             if (isset($ctxt_mes_text[$i]) && isset($ctxt_mes_x[$i]) && isset($ctxt_mes_y[$i]) && isset($ctxt_mes_h[$i]) && isset($ctxt_mes_font[$i]) && isset($ctxt_mes_shadow_hid[$i]) && $ctxt_mes_text[$i]) {
                 $crtf_shadow = $ctxt_mes_shadow_hid[$i] ? 1 : 0;
                 $crtf_font = '';
                 $text_x = intval($ctxt_mes_x[$i]);
                 if ($text_x < 0) {
                     $text_x = 0;
                 }
                 $text_y = intval($ctxt_mes_y[$i]);
                 if ($text_y < 0) {
                     $text_y = 0;
                 }
                 $text_size = intval($ctxt_mes_h[$i]);
                 if ($text_size < 0) {
                     $text_size = 0;
                 }
                 $crtf_text = $ctxt_mes_text[$i];
                 $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                 $crtf_text = ampReplace(strip_tags($crtf_text));
                 $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                 $crtf_font = strval($ctxt_mes_font[$i]);
                 if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                     $crtf_font = 'arial.ttf';
                 }
                 if (!$cmid) {
                     $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size, crtf_type, crtf_font) VALUES ( {$crtf_id}, '" . $course_id . "', '', '" . $crtf_text . "', " . $i . ", {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "', '-2', " . $JLMS_DB->quote($crtf_font) . ")";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $crtf_cmes_id = $JLMS_DB->insertid();
                     /*echo $JLMS_DB->geterrormsg();*/
                     $add_cmes_ids[] = $crtf_cmes_id;
                 } else {
                     $query = "UPDATE #__lms_certificates SET crtf_text = '" . $crtf_text . "', crtf_align = {$i}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . " WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id = {$crtf_id} AND id = {$cmid}";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $add_cmes_ids[] = $cmid;
                 }
             }
             $i++;
         }
         if (empty($add_cmes_ids)) {
             $add_cmes_ids = array(0);
         }
         /*print_r($add_cmes_ids);*/
         $add_cmes_ids_t = implode(',', $add_cmes_ids);
         $query = "DELETE FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crtf_id} AND crtf_type = '-2' AND id NOT IN ({$add_cmes_ids_t})";
         $JLMS_DB->SetQuery($query);
         $JLMS_DB->query();
         /*die;*/
         /* end of 'custom text fields' mod */
         if ($crtf_id) {
             $JLMS_ACL =& JLMSFactory::getACL();
             $lroles = $JLMS_ACL->GetSystemRolesIds(1);
             $add_certificates = josGetArrayInts('certificate_types', $_REQUEST);
             $types = array();
             if (!empty($add_certificates)) {
                 foreach ($add_certificates as $add_cert) {
                     if ($add_cert && in_array($add_cert, $lroles)) {
                         $certificate_default = intval(mosGetParam($_REQUEST, 'certificate_default_' . $add_cert, 0));
                         if (!$certificate_default) {
                             $crtf_text = isset($_REQUEST['crtf_text_' . $add_cert]) ? $_REQUEST['crtf_text_' . $add_cert] : '';
                             $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                             $crtf_text = ampReplace(strip_tags($crtf_text));
                             $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                             $crtf_align = intval(mosGetParam($_REQUEST, 'crtf_align_' . $add_cert, 0));
                             $crtf_shadow = intval(mosGetParam($_REQUEST, 'crtf_shadow_' . $add_cert, 0));
                             $crtf_font = strval(mosGetParam($_REQUEST, 'crtf_font_' . $add_cert, 0));
                             if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                                 $crtf_font = 'arial.ttf';
                             }
                             if ($crtf_shadow) {
                                 $crtf_shadow = 1;
                             }
                             if (!in_array($crtf_align, array(0, 1, 2))) {
                                 $crtf_align = 0;
                             }
                             $text_x = intval(mosGetParam($_REQUEST, 'text_x_' . $add_cert, 0));
                             $text_y = intval(mosGetParam($_REQUEST, 'text_y_' . $add_cert, 0));
                             $text_size = intval(mosGetParam($_REQUEST, 'text_size_' . $add_cert, 0));
                             $new_file = false;
                             $file_id = 0;
                             if (isset($_FILES['userfile_' . $add_cert]) && !empty($_FILES['userfile_' . $add_cert]['name'])) {
                                 $file_id = JLMS_uploadFile($course_id, 'userfile_' . $add_cert);
                                 $new_file = true;
                             }
                             $query = "SELECT * FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $add_cert . "' AND parent_id = {$crtf_id}";
                             $JLMS_DB->SetQuery($query);
                             $old_crt = $JLMS_DB->LoadObjectList();
                             if (count($old_crt)) {
                                 $old_file = $old_crt[0]->file_id;
                                 if ($old_file && $new_file) {
                                     $files = array();
                                     $files[] = $old_file;
                                     JLMS_deleteFiles($files);
                                 }
                                 $crtf_id_c = $old_crt[0]->id;
                                 $query = "UPDATE #__lms_certificates SET crtf_name = '" . $crtf_name . "', crtf_text = '" . $crtf_text . "', crtf_align = {$crtf_align}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . "" . ($new_file ? ", file_id = '" . $file_id . "'" : '') . " WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $add_cert . "' AND parent_id = {$crtf_id}";
                                 $JLMS_DB->SetQuery($query);
                                 $JLMS_DB->query();
                             } else {
                                 $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size" . ($new_file ? ", file_id" : '') . ", crtf_type, crtf_font) VALUES ( {$crtf_id}, '" . $course_id . "', '" . $crtf_name . "', '" . $crtf_text . "', {$crtf_align}, {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "'" . ($new_file ? ",'" . $file_id . "'" : '') . ", '" . $add_cert . "', " . $JLMS_DB->quote($crtf_font) . ")";
                                 $JLMS_DB->SetQuery($query);
                                 $JLMS_DB->query();
                                 $crtf_id_c = $JLMS_DB->insertid();
                             }
                             /* 23 october 2007 - (DEN) */
                             /* handle custom text fields */
                             $ctxt_mes_ids = josGetArrayInts('ctxt_mes_id_' . $add_cert, $_REQUEST);
                             $ctxt_mes_text = isset($_REQUEST['ctxt_mes_text_' . $add_cert]) ? $_REQUEST['ctxt_mes_text_' . $add_cert] : array();
                             $ctxt_mes_shadow_hid = mosGetParam($_REQUEST, 'ctxt_mes_shadow_hid_' . $add_cert, array());
                             $ctxt_mes_x = mosGetParam($_REQUEST, 'ctxt_mes_x_' . $add_cert, array());
                             $ctxt_mes_y = mosGetParam($_REQUEST, 'ctxt_mes_y_' . $add_cert, array());
                             $ctxt_mes_h = mosGetParam($_REQUEST, 'ctxt_mes_h_' . $add_cert, array());
                             $ctxt_mes_font = mosGetParam($_REQUEST, 'ctxt_mes_font_' . $add_cert, array());
                             $p_ids = array();
                             $i = 0;
                             $add_cmes_ids = array();
                             foreach ($ctxt_mes_ids as $cmid) {
                                 if (isset($ctxt_mes_text[$i]) && isset($ctxt_mes_x[$i]) && isset($ctxt_mes_y[$i]) && isset($ctxt_mes_h[$i]) && isset($ctxt_mes_font[$i]) && isset($ctxt_mes_shadow_hid[$i]) && $ctxt_mes_text[$i]) {
                                     $crtf_shadow = $ctxt_mes_shadow_hid[$i] ? 1 : 0;
                                     $crtf_font = '';
                                     $text_x = intval($ctxt_mes_x[$i]);
                                     if ($text_x < 0) {
                                         $text_x = 0;
                                     }
                                     $text_y = intval($ctxt_mes_y[$i]);
                                     if ($text_y < 0) {
                                         $text_y = 0;
                                     }
                                     $text_size = intval($ctxt_mes_h[$i]);
                                     if ($text_size < 0) {
                                         $text_size = 0;
                                     }
                                     $crtf_text = $ctxt_mes_text[$i];
                                     $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                                     $crtf_text = ampReplace(strip_tags($crtf_text));
                                     $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                                     $crtf_font = strval($ctxt_mes_font[$i]);
                                     if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                                         $crtf_font = 'arial.ttf';
                                     }
                                     if (!$cmid) {
                                         $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size, crtf_type, crtf_font) VALUES ( {$crtf_id_c}, '" . $course_id . "', '', '" . $crtf_text . "', " . $i . ", {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "', '-2', " . $JLMS_DB->quote($crtf_font) . ")";
                                         $JLMS_DB->SetQuery($query);
                                         $JLMS_DB->query();
                                         $crtf_cmes_id = $JLMS_DB->insertid();
                                         $add_cmes_ids[] = $crtf_cmes_id;
                                     } else {
                                         $query = "UPDATE #__lms_certificates SET crtf_text = '" . $crtf_text . "', crtf_align = {$i}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . " WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id = {$crtf_id_c} AND id = {$cmid}";
                                         $JLMS_DB->SetQuery($query);
                                         $JLMS_DB->query();
                                         $add_cmes_ids[] = $cmid;
                                     }
                                 }
                                 $i++;
                             }
                             if (empty($add_cmes_ids)) {
                                 $add_cmes_ids = array(0);
                             }
                             $add_cmes_ids_t = implode(',', $add_cmes_ids);
                             $query = "DELETE FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crtf_id_c} AND crtf_type = '-2' AND id NOT IN ({$add_cmes_ids_t})";
                             $JLMS_DB->SetQuery($query);
                             $JLMS_DB->query();
                             /* end of 'custom text fields' mod */
                             $types[] = $add_cert;
                         }
                     }
                 }
             }
             if (empty($types)) {
                 $types = array(-2);
             } else {
                 $types[] = -2;
             }
             /*print_r($types);*/
             $types_str = implode(',', $types);
             $query = "SELECT id, file_id FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type NOT IN ({$types_str}) AND parent_id = {$crtf_id}";
             $JLMS_DB->SetQuery($query);
             $old_sec_certs = $JLMS_DB->LoadObjectList();
             $old_files = array();
             $old_sec_cert_ids = array();
             if (!empty($old_sec_certs)) {
                 foreach ($old_sec_certs as $osc) {
                     $old_files[] = $osc->file_id;
                     $old_sec_cert_ids[] = $osc->id;
                 }
                 JLMS_deleteFiles($old_files);
             }
             $query = "DELETE FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type NOT IN ({$types_str}) AND parent_id = {$crtf_id}";
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
             if (!empty($old_sec_cert_ids)) {
                 $osc_t = implode(',', $old_sec_cert_ids);
                 $query = "DELETE FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id IN ({$osc_t})";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
             }
         }
     }
     /*die;*/
     if (!$redirect_url) {
         $redirect_url = "index.php?option={$option}&Itemid={$Itemid}&task=gb_certificates&id={$course_id}";
     }
     JLMSRedirect(sefRelToAbs(str_replace('{id}', $crtf_id, $redirect_url)));
 }
Esempio n. 3
0
function JLMS_DelOp_deleteCourse($id)
{
    global $JLMS_DB, $JLMS_CONFIG;
    $course_id = $id;
    $files_ids = array();
    @set_time_limit('3000');
    $query = "DELETE FROM #__lms_agenda WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_attendance WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_certificate_users WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "SELECT distinct file_id FROM #__lms_certificates WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $cert_files = $JLMS_DB->LoadResultArray();
    $query = "DELETE FROM #__lms_certificates WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_chat_history WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_chat_users WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_conference_doc WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    /* added 05.09.2007 by DEN */
    $query = "DELETE FROM #__lms_subscriptions_courses WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $doc_files = array();
    $zip_docs = array();
    $doc_ids = array();
    $query = "SELECT id, file_id, folder_flag FROM #__lms_documents WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $docs_info = $JLMS_DB->LoadObjectList();
    foreach ($docs_info as $di) {
        if ($di->folder_flag == 2 && $di->file_id) {
            $zip_docs[] = $di->file_id;
            $doc_ids[] = $di->id;
        } elseif (!$di->folder_flag && $di->file_id) {
            $doc_files[] = $di->file_id;
            $doc_ids[] = $di->id;
        }
    }
    $doc_files = array_unique($doc_files);
    $query = "DELETE FROM #__lms_documents WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "SELECT distinct file_id FROM #__lms_dropbox WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $dropbox_files = $JLMS_DB->LoadResultArray();
    $query = "DELETE FROM #__lms_dropbox WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $files_ids = array_merge($doc_files, $dropbox_files);
    $files_ids = array_merge($files_ids, $cert_files);
    if (count($files_ids)) {
        JLMS_deleteFiles($files_ids);
    }
    $query = "DELETE FROM #__lms_forum_details WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_gradebook WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_gradebook_items WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_homework WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_homework_results WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_learn_path_conds WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_learn_path_grades WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "SELECT id FROM #__lms_learn_path_results WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $result_cid = $JLMS_DB->LoadResultArray();
    if (count($result_cid)) {
        $result_cids = implode(',', $result_cid);
        $query = "DELETE FROM #__lms_learn_path_results WHERE course_id = '" . $course_id . "'";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        $query = "DELETE FROM #__lms_learn_path_step_results WHERE result_id IN ({$result_cids})";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        // 05.03.2007 (dleting of lp quiz results)
        $query = "DELETE FROM #__lms_learn_path_step_quiz_results WHERE result_id IN ({$result_cids})";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
    }
    $query = "DELETE FROM #__lms_learn_path_steps WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "SELECT id FROM #__lms_learn_paths WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $lp_cid = $JLMS_DB->LoadResultArray();
    if (count($lp_cid)) {
        $lp_cids = implode(',', $lp_cid);
        $query = "DELETE FROM #__lms_learn_path_prerequisites WHERE lpath_id IN ({$lp_cids}) OR req_id IN ({$lp_cids})";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
    }
    $query = "DELETE FROM #__lms_learn_paths WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_links WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    # !!!!!!!!! lms_payments !!!!!!!!! # ??????????????????
    // QUIZZES section
    $query = "SELECT c_id FROM #__lms_quiz_t_quiz WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->setQuery($query);
    $cid_quiz = $JLMS_DB->LoadResultArray();
    if (count($cid_quiz)) {
        $cids_quiz = implode(',', $cid_quiz);
        $query = "DELETE FROM #__lms_quiz_t_quiz WHERE c_id IN ( {$cids_quiz} )";
        $JLMS_DB->setQuery($query);
        $JLMS_DB->query();
        $query = "SELECT c_id FROM #__lms_quiz_t_question WHERE c_quiz_id IN ( {$cids_quiz} ) AND course_id = '" . $course_id . "'";
        $JLMS_DB->SetQuery($query);
        $cid_quest = $JLMS_DB->LoadResultArray();
        if (count($cid_quest)) {
            $cids_quest = implode(',', $cid_quest);
            $query = "DELETE FROM #__lms_quiz_t_question WHERE c_id IN ( {$cids_quest} )";
            $JLMS_DB->setQuery($query);
            $JLMS_DB->query();
            $query = "DELETE FROM #__lms_quiz_t_choice WHERE c_question_id IN ( {$cids_quest} )";
            $JLMS_DB->setQuery($query);
            $JLMS_DB->query();
            $query = "DELETE FROM #__lms_quiz_t_hotspot WHERE c_question_id IN ( {$cids_quest} )";
            $JLMS_DB->setQuery($query);
            $JLMS_DB->query();
            $query = "DELETE FROM #__lms_quiz_t_matching WHERE c_question_id IN ( {$cids_quest} )";
            $JLMS_DB->setQuery($query);
            $JLMS_DB->query();
            $query = "SELECT c_id FROM #__lms_quiz_t_blank WHERE c_question_id IN ( {$cids_quest} )";
            $JLMS_DB->SetQuery($query);
            $blank_cid = $JLMS_DB->LoadResultArray();
            $query = "DELETE FROM #__lms_quiz_t_blank WHERE c_question_id IN ( {$cids_quest} )";
            $JLMS_DB->setQuery($query);
            $JLMS_DB->query();
            if (count($blank_cid)) {
                $blank_cids = implode(',', $blank_cid);
                $query = "DELETE FROM #__lms_quiz_t_text WHERE c_blank_id IN ( {$blank_cids} )";
                $JLMS_DB->setQuery($query);
                $JLMS_DB->query();
            }
        }
    }
    $query = "SELECT * FROM #__lms_scorm_packages WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $scorm_info = $JLMS_DB->LoadObjectList();
    if (count($scorm_info)) {
        $scorm_cid = array();
        foreach ($scorm_info as $si) {
            $scorm_cid[] = $si->id;
        }
        $scorm_cids = implode(',', $scorm_cid);
        $query = "DELETE FROM #__lms_scorm_packages WHERE course_id = '" . $course_id . "'";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        $query = "DELETE FROM #__lms_scorm_sco WHERE content_id IN ({$scorm_cids})";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        require_once _JOOMLMS_FRONT_HOME . "/includes/jlms_dir_operation.php";
        $scorm_folder = $JLMS_CONFIG->getCfg('absolute_path') . "/" . _JOOMLMS_SCORM_FOLDER . "/";
        foreach ($scorm_info as $del_scorm) {
            deldir($scorm_folder . $del_scorm->folder_srv_name . "/");
            @unlink($scorm_folder . $del_scorm->package_srv_name);
        }
    }
    if (count($zip_docs)) {
        $zds = implode(',', $zip_docs);
        $query = "SELECT * FROM #__lms_documents_zip WHERE id IN ({$zds}) AND course_id = '" . $course_id . "'";
        $JLMS_DB->SetQuery($query);
        $zippacks_info = $JLMS_DB->LoadObjectList();
        if (count($zippacks_info)) {
            $zippack_cid = array();
            foreach ($zippacks_info as $zi) {
                $zippack_cid[] = $zi->id;
            }
            $zippack_cids = implode(',', $zippack_cid);
            $query = "DELETE FROM #__lms_documents_zip WHERE id IN ({$zippack_cids}) AND course_id = '" . $course_id . "'";
            $JLMS_DB->SetQuery($query);
            $JLMS_DB->query();
            require_once _JOOMLMS_FRONT_HOME . "/includes/jlms_dir_operation.php";
            $zp_folder = $JLMS_CONFIG->getCfg('absolute_path') . "/" . _JOOMLMS_SCORM_FOLDER . "/";
            foreach ($zippacks_info as $del_zp) {
                deldir($zp_folder . $del_zp->zip_folder . "/");
                @unlink($zp_folder . $del_zp->zip_srv_name);
            }
        }
    }
    $query = "DELETE FROM #__lms_track_chat WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    if (count($doc_ids)) {
        $cid_docs = implode(',', $doc_ids);
        $query = "DELETE FROM #__lms_track_downloads WHERE doc_id IN ({$cid_docs})";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
    }
    $query = "DELETE FROM #__lms_track_hits WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_track_learnpath_stats WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_usergroups WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_users_in_groups WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_user_courses WHERE course_id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
    $query = "DELETE FROM #__lms_courses WHERE id = '" . $course_id . "'";
    $JLMS_DB->SetQuery($query);
    $JLMS_DB->query();
}
 function JQ_ImgsList_del($cid, $option, $page, $course_id)
 {
     global $JLMS_DB, $JLMS_CONFIG, $Itemid;
     $course_id = $JLMS_CONFIG->get('course_id');
     $usertype = $JLMS_CONFIG->get('current_usertype', 0);
     if ($course_id && $usertype == 1) {
         if (count($cid)) {
             $cids = implode(',', $cid);
             $query = "SELECT * FROM #__lms_quiz_images WHERE c_id IN ( {$cids} ) AND course_id = '" . $course_id . "'";
             $JLMS_DB->setQuery($query);
             $row = $JLMS_DB->loadObjectList();
             $files = array();
             $k = 0;
             foreach ($row as $data) {
                 $files[$k] = $data->imgs_id;
                 $k++;
             }
             JLMS_deleteFiles($files);
             $query = "DELETE FROM #__lms_quiz_images" . "\n WHERE c_id IN ( {$cids} ) AND course_id = '" . $course_id . "'";
             $JLMS_DB->setQuery($query);
             if (!$JLMS_DB->query()) {
                 echo "<script> alert('" . $JLMS_DB->getErrorMsg() . "'); window.history.go(-1); </script>\n";
             }
         }
     }
     JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&id={$course_id}&page=imgs"));
 }
Esempio n. 5
0
function JLMS_uploadFileHW($option, $callFromCode = false)
{
    global $JLMS_DB, $my, $Itemid;
    $id = JRequest::getInt('id');
    $hw_id = JRequest::getInt('hw_id');
    $course_id = JRequest::getInt('course_id');
    $userfile = JRequest::getVar('userfile', '', 'FILES');
    $JLMS_ACL =& JLMSFactory::getACL();
    if (!isset($userfile['name']) || isset($userfile['name']) && empty($userfile['name'])) {
        return false;
    }
    $res_id = 0;
    if ($JLMS_ACL->CheckPermissions('homework', 'view') && ($hw_id && JLMS_GetHWCourse($hw_id) == $course_id)) {
        $row = new mos_JLMS_HomeWork_Result($JLMS_DB);
        if (!$row->loadExt($course_id, $hw_id, $my->id)) {
            $row->course_id = $course_id;
            $row->user_id = $my->id;
            $row->hw_id = $hw_id;
            $row->file_id = 0;
        }
        $row->hw_date = date('Y-m-d H:i:s');
        $file_id = JLMS_uploadFile($course_id);
        if ($file_id) {
            if ($row->file_id) {
                JLMS_deleteFiles($row->file_id);
            }
            $row->file_id = $file_id;
            $row->store();
        }
        $res_id = $row->id;
    }
    if ($callFromCode) {
        return $res_id;
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=hw_view&course_id={$course_id}&id={$hw_id}"));
    }
}