function jlms_conference_upload($option, $id) { global $my, $Itemid, $JLMS_DB, $JLMS_CONFIG; ?> <script type="text/javascript" src="<?php echo $JLMS_CONFIG->get('live_site'); ?> '/components/com_joomla_lms/includes/js/swfobject.js"></script>'); <script type="text/javascript"> function test(){ //alert('test'); } </script> <?php $file_id = JLMS_uploadFile($course_id, 'fichier'); if (!$file_id) { echo "<script> alert('Upload failed or file extension is not supported.'); window.history.go(-1); </script>\n"; exit; } else { $query = "INSERT INTO `#__lms_conference_doc` (course_id, owner_id, upload_type, filename, file_id) VALUES (" . intval($id) . ", " . (int) $my->id . ", 1, '" . $_FILES['fichier']['name'] . "', " . intval($file_id) . " )"; $JLMS_DB->setQuery($query); //$JLMS_DB->getErrorMsg(); if ($JLMS_DB->query()) { $file_id = $JLMS_DB->insertid(); ?> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="300" height="300" id="upload" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="<?php echo $JLMS_CONFIG->get('live_site'); ?> /components/com_joomla_lms/includes/conference/upload_106.swf?fileName=<?php echo urlencode(utf8_encode($_FILES['fichier']['name'])) . "&course_id=" . $id . "&file_id=" . $file_id; ?> " /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="<?php echo $JLMS_CONFIG->get('live_site'); ?> /components/com_joomla_lms/includes/conference/upload_106.swf?fileName=<?php echo urlencode(utf8_encode($_FILES['fichier']['name'])) . "&course_id=" . $id . "&file_id=" . $file_id; ?> " quality="high" bgcolor="#ffffff" width="300" height="300" name="upload" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> <?php } } }
function JLMS_saveDropBox($option) { $JLMS_CONFIG =& JLMSFactory::getConfig(); $Itemid = $JLMS_CONFIG->get('Itemid'); $_JLMS_PLUGINS =& JLMSFactory::getPlugins(); $db =& JFactory::getDbo(); $user = JLMSFactory::getUser(); $course_id = intval(mosGetParam($_REQUEST, 'course_id', 0)); // if ($user->get('id') && $course_id && JLMS_GetUserType($user->get('id'), $course_id) ) { $JLMS_ACL =& JLMSFactory::getACL(); if ($user->get('id') && $course_id && $JLMS_ACL->CheckPermissions('dropbox', 'view')) { $recv_id = intval(mosGetParam($_REQUEST, 'recv_id', 0)); $recv_id = mosGetParam($_POST, 'recv_id', array(0)); if (!is_array($recv_id)) { $recv_id = array(0); } if (isset($recv_id[0]) && !$recv_id[0] || !count($recv_id)) { //fix one user (ticket [QDHZ-1096]) $msg = _JLMS_DROP_ERROR_NO_SEND_TO; JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}"), $msg); } //convert array of receiver's to numeric values $i = 0; while ($i < count($recv_id)) { $recv_id[$i] = intval($recv_id[$i]); $i++; } $recv_ids = implode(',', $recv_id); $do_continue = false; /* New permissions (Max) */ $query = "SELECT count(user_id) FROM #__lms_user_courses" . "\n WHERE course_id = '" . $course_id . "' AND user_id IN ( {$recv_ids} )"; $db->setQuery($query); $count_users = $db->LoadResult(); if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_teachers')) { if ($count_users) { $do_continue = true; } else { $query = "SELECT count(c.user_id) FROM #__lms_users_in_groups as c" . "\n WHERE c.course_id = '" . $course_id . "' AND c.user_id IN ( {$recv_ids} )"; $db->setQuery($query); $count_users = $db->LoadResult(); if ($count_users) { $do_continue = true; } } } if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_learners')) { if ($count_users) { $do_continue = true; } } /* Old part */ /* if (JLMS_GetUserType($user->get('id'), $course_id) == 1) { $query = "SELECT count(user_id) FROM #__lms_user_courses" . "\n WHERE course_id = '".$course_id."' AND (role_id = 1 OR role_id = 4) AND user_id IN ( $recv_ids )"; $db->setQuery($query); $count_users = $db->LoadResult(); if ($count_users) { $do_continue = true; } else { $query = "SELECT count(c.user_id) FROM #__lms_users_in_groups as c" . "\n WHERE c.course_id = '".$course_id."' AND c.user_id IN ( $recv_ids )"; $db->setQuery($query); $count_users = $db->LoadResult(); if ($count_users) { $do_continue = true; } } } elseif (JLMS_GetUserType($user->get('id'), $course_id) == 2) { $query = "SELECT count(user_id) FROM #__lms_user_courses" . "\n WHERE course_id = '".$course_id."' AND (role_id = 1 OR role_id = 4) AND user_id IN ( $recv_ids )"; $db->setQuery($query); $count_users = $db->LoadResult(); if ($count_users) { $do_continue = true; } } */ // (TIPS) // sender: teacher - RECEIVER must be teacher of this course or student of this course // sender: student - RECEIVER must be teacher of this course $flag = false; if ($do_continue) { if ($_FILES['userfile']['name'] == '') { $file_id = 0; $flag = true; } else { $file_id = JLMS_uploadFile($course_id); if ($file_id) { $flag = true; } } $_POST['drp_type'] = 1; if (intval(mosGetParam($_REQUEST, 'file_id', 0))) { $file_id = intval(mosGetParam($_REQUEST, 'file_id', 0)); $_POST['drp_type'] = 2; } if ($flag) { $row = new mos_Joomla_LMS_DropBox($db); if (!$row->bind($_POST)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } $row->file_id = $file_id; $row->owner_id = $user->get('id'); $row->drp_mark = 1; /*$query = "SELECT file_name FROM #__lms_files WHERE id = '".$file_id."'"; $db->SetQuery( $query ); $row->drp_name = $db->LoadResult();*/ //$row->drp_name = strval(mosGetParam($_FILES['userfile'], 'name', 'dropbox_file')); if ($file_id > 0) { if ($row->drp_type == 1) { $drp_name = isset($_FILES['userfile']['name']) ? strval($_FILES['userfile']['name']) : 'dropbox_file'; } else { if ($row->drp_type == 2) { $drp_name = strval(mosGetParam($_REQUEST, 'dropbox_name', 'dropbox_file_(' . time() . ')')); } } } else { $drp_name = mosGetParam($_REQUEST, 'dropbox_name'); } $drp_name = get_magic_quotes_gpc() ? stripslashes($drp_name) : $drp_name; $row->drp_name = ampReplace(strip_tags($drp_name)); $row->drp_description = strval(JLMS_getParam_LowFilter($_POST, 'drp_description', '')); //$row->drp_description = JLMS_ProcessText_LowFilter($row->drp_description); // if (JLMS_GetUserType($user->get('id'), $course_id ) == 1) { if ($JLMS_ACL->CheckPermissions('dropbox', 'mark_as_corrected')) { $drp_corr = intval(mosGetParam($_REQUEST, 'drp_corrected', 0)); if ($drp_corr != 1) { $drp_corr = 0; } $row->drp_corrected = $drp_corr; } else { $row->drp_corrected = 0; } $row->drp_time = date('Y-m-d H:i:s'); //Replace old function JLMS_GetUserType //tmp $users_teachers = array(); $users_learners = array(); if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_teachers')) { $query = "SELECT a.* FROM #__users as a, #__lms_user_courses as c" . "\n WHERE a.id = c.user_id AND c.course_id = '" . $course_id . "' AND a.id <> '" . $user->id . "'" . "\n ORDER BY a.username"; $db->SetQuery($query); $users_teachers = $db->LoadObjectList(); $i = 0; while ($i < count($users_teachers)) { $users_teachers[$i]->username = _JLMS_ROLE_TEACHER . ' - ' . $users_teachers[$i]->name . ' (' . $users_teachers[$i]->username . ')'; $i++; } } if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_learners')) { $users_learners = JLMS_getCourseStudentsList($course_id); } $tmp = array(); foreach ($users_teachers as $n => $ut) { $tmp[$n] = $ut->id; } if (count($tmp)) { $users_teachers = $tmp; } $tmp = array(); foreach ($users_learners as $n => $ul) { $tmp[$n] = $ul->id; } if (count($tmp)) { $users_learners = $tmp; } //Replace old function JLMS_GetUserType //tmp foreach ($recv_id as $recv) { $check_recv = false; //Replace old function JLMS_GetUserType //tmp if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_teachers') && in_array($recv, $users_teachers)) { $check_recv = true; } if ($JLMS_ACL->CheckPermissions('dropbox', 'send_to_learners') && in_array($recv, $users_learners)) { $check_recv = true; } //Replace old function JLMS_GetUserType //tmp // if ($recv && ($recv != $user->get('id')) && ((JLMS_GetUserType($user->get('id'), $course_id) == 1 && JLMS_GetUserType($recv, $course_id)) || ((JLMS_GetUserType($user->get('id'), $course_id) == 2) && (JLMS_GetUserType($recv, $course_id, true) == 1))) || ((JLMS_GetUserType($user->get('id'), $course_id) == 2) && (JLMS_GetUserType($recv, $course_id, true) == 2)) ) { //old if ($recv && $recv != $user->get('id') && $check_recv) { $row->id = 0; $row->recv_id = $recv; 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; } //*** send email notification $e_course = new stdClass(); $e_course->course_alias = ''; $e_course->course_name = ''; $query = "SELECT course_name, name_alias FROM #__lms_courses WHERE id = '" . $course_id . "'"; $db->setQuery($query); $e_course = $db->loadObject(); $e_user = new stdClass(); $e_user->name = ''; $e_user->email = ''; $e_user->username = ''; $query = "SELECT email, name, username FROM #__users WHERE id = '" . $recv . "'"; $db->setQuery($query); $e_user = $db->loadObject(); $e_params['user_id'] = $recv; $e_params['course_id'] = $course_id; $e_params['markers']['{email}'] = $e_user->email; $e_params['markers']['{name}'] = $e_user->name; $e_params['markers']['{username}'] = $e_user->username; $e_params['markers']['{coursename}'] = $e_course->course_name; //( $e_course->course_alias )?$e_course->course_alias:$e_course->course_name; $e_params['markers']['{filename}'] = $row->drp_name; $e_params['markers']['{courselink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}&task=details_course&id={$course_id}"); $e_params['markers_nohtml']['{courselink}'] = $e_params['markers']['{courselink}']; $e_params['markers']['{courselink}'] = '<a href="' . $e_params['markers']['{courselink}'] . '">' . $e_params['markers']['{courselink}'] . '</a>'; $e_params['markers']['{lmslink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}"); $e_params['markers_nohtml']['{lmslink}'] = $e_params['markers']['{lmslink}']; $e_params['markers']['{lmslink}'] = '<a href="' . $e_params['markers']['{lmslink}'] . '">' . $e_params['markers']['{lmslink}'] . '</a>'; $e_params['action_name'] = 'OnNewDropboxFile'; $_JLMS_PLUGINS->loadBotGroup('emails'); $plugin_result_array = $_JLMS_PLUGINS->trigger('OnNewDropboxFile', array(&$e_params)); //*** end of emails } } JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}")); } else { mosErrorAlert("Upload of " . $userfile_name . " failed"); } } else { JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}")); } } else { JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}")); } }
function JQ_ImgsList_save($option) { // Axtung!: vse tablicy nabora question options (like 't_choice', 't_matching') are stores imgs_id instead of id from #__lms_quiz_images global $my, $JLMS_DB, $Itemid, $JLMS_CONFIG; $JLMS_ACL =& JLMSFactory::getACL(); $course_id = $JLMS_CONFIG->get('course_id'); $c_id = intval(mosGetParam($_REQUEST, 'c_id', 0)); $imgs_name_post = isset($_REQUEST['imgs_name']) ? strval($_REQUEST['imgs_name']) : 'imgs_name'; $imgs_name_post = get_magic_quotes_gpc() ? stripslashes($imgs_name_post) : $imgs_name_post; $imgs_name_post = ampReplace(strip_tags($imgs_name_post)); if (!$c_id) { $file_id = 0; if (isset($_FILES['imgs']) && !empty($_FILES['imgs']['name'])) { $file_id = JLMS_uploadFile($course_id, 'imgs'); } if ($file_id) { $query = "INSERT #__lms_quiz_images (imgs_name, imgs_id, course_id)" . "\n VALUES ('" . $imgs_name_post . "', '" . $file_id . "', '" . $course_id . "' )"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } else { $query = "UPDATE #__lms_quiz_images SET imgs_name = '" . $imgs_name_post . "' WHERE c_id = '" . $c_id . "'"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&page=imgs&id={$course_id}")); }
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))); }
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}")); } }