/** * @Security("has_role('ROLE_ADMIN')") * @Route("/plugins/add") * * @return array */ public function pluginsAddAction() { $appPlugin = new \AppPlugin(); $allPlugins = $appPlugin->read_plugins_from_path(); $allPluginsList = []; foreach ($allPlugins as $pluginName) { $file = api_get_path(SYS_PLUGIN_PATH) . $pluginName . '/plugin.php'; if (is_file($file)) { $pluginInfo = (require $file); var_dump($pluginInfo); exit; $allPluginsList[] = $pluginInfo; } } $installedPlugins = $appPlugin->get_installed_plugins(); $manager = $this->getSettingsManager(); $schemas = $manager->getSchemas(); return $this->render('@ChamiloCore/Admin/Settings/pluginsAdd.html.twig', array('plugins' => $allPluginsList, 'installed_plugins' => $installedPlugins)); }
/** * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully) * Sender name and email can be specified, if not specified * name and email of the platform admin are used * * @author Bert Vanderkimpen ICT&O UGent * @author Yannick Warnier <*****@*****.**> * * @param string name of recipient * @param string email of recipient * @param string email subject * @param string email body * @param string sender name * @param string sender e-mail * @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array data file (path and filename) * @param array data to attach a file (optional) * @param bool True for attaching a embedded file inside content html (optional) * @return returns true if mail was sent * @see class.phpmailer.php */ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $senderName = '', $senderEmail = '', $extra_headers = array(), $data_file = array(), $embedded_image = false, $additionalParameters = array()) { global $platform_email; $mail = new PHPMailer(); $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; $mail->CharSet = $platform_email['SMTP_CHARSET']; // Stay far below SMTP protocol 980 chars limit. $mail->WordWrap = 200; if ($platform_email['SMTP_AUTH']) { $mail->SMTPAuth = 1; $mail->Username = $platform_email['SMTP_USER']; $mail->Password = $platform_email['SMTP_PASS']; } // 5 = low, 1 = high $mail->Priority = 3; $mail->SMTPKeepAlive = true; // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // Error to admin. $mail->AddCustomHeader('Errors-To: ' . $defaultEmail); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultEmail; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultName; // Reply to first if (isset($extra_headers['reply_to'])) { $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); $mail->Sender = $extra_headers['reply_to']['mail']; unset($extra_headers['reply_to']); } $mail->SetFrom($senderEmail, $senderName); $mail->Subject = $subject; $mail->AltBody = strip_tags(str_replace('<br />', "\n", api_html_entity_decode($message))); // Send embedded image. if ($embedded_image) { // Get all images html inside content. preg_match_all("/<img\\s+.*?src=[\"\\']?([^\"\\' >]*)[\"\\']?[^>]*>/i", $message, $m); // Prepare new tag images. $new_images_html = array(); $i = 1; if (!empty($m[1])) { foreach ($m[1] as $image_path) { $real_path = realpath($image_path); $filename = basename($image_path); $image_cid = $filename . '_' . $i; $encoding = 'base64'; $image_type = mime_content_type($real_path); $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); $new_images_html[] = '<img src="cid:' . $image_cid . '" />'; $i++; } } // Replace origin image for new embedded image html. $x = 0; if (!empty($m[0])) { foreach ($m[0] as $orig_img) { $message = str_replace($orig_img, $new_images_html[$x], $message); $x++; } } } $message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message); $mail->Body = '<html><head></head><body>' . $message . '</body></html>'; // Attachment ... if (!empty($data_file)) { $mail->AddAttachment($data_file['path'], $data_file['filename']); } // Only valid addresses are accepted. if (is_array($recipient_email)) { foreach ($recipient_email as $dest) { if (api_valid_email($dest)) { $mail->AddAddress($dest, $recipient_name); } } } else { if (api_valid_email($recipient_email)) { $mail->AddAddress($recipient_email, $recipient_name); } else { return 0; } } if (is_array($extra_headers) && count($extra_headers) > 0) { foreach ($extra_headers as $key => $value) { switch (strtolower($key)) { case 'encoding': case 'content-transfer-encoding': $mail->Encoding = $value; break; case 'charset': $mail->Charset = $value; break; case 'contenttype': case 'content-type': $mail->ContentType = $value; break; default: $mail->AddCustomHeader($key . ':' . $value); break; } } } else { if (!empty($extra_headers)) { $mail->AddCustomHeader($extra_headers); } } // WordWrap the html body (phpMailer only fixes AltBody) FS#2988 $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap); // Send the mail message. if (!$mail->Send()) { error_log('ERROR: mail not sent to ' . $recipient_name . ' (' . $recipient_email . ') because of ' . $mail->ErrorInfo . '<br />'); return 0; } $plugin = new AppPlugin(); $installedPluginsList = $plugin->getInstalledPluginListObject(); foreach ($installedPluginsList as $installedPlugin) { if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additionalParameters)) { $clockworksmsObject = new Clockworksms(); $clockworksmsObject->send($additionalParameters); } } // Clear all the addresses. $mail->ClearAddresses(); return 1; }
<?php /* For licensing terms, see /license.txt */ require_once '../../main/inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; api_protect_course_script(); $plugin = new AppPlugin(); $pluginList = $plugin->get_installed_plugins(); $capturePluginInstalled = in_array('jcapture', $pluginList); if (!$capturePluginInstalled) { exit; } if (!isset($_FILES['Filedata'])) { exit; } $courseInfo = api_get_course_info(); $folderName = 'captures'; $documentId = DocumentManager::get_document_id($courseInfo, '/'.$folderName); $path = null; if (empty($documentId)) { $course_dir = $courseInfo['path'] . '/document'; $sys_course_path = api_get_path(SYS_COURSE_PATH); $dir = $sys_course_path . $course_dir; $createdDir = create_unexisting_directory( $courseInfo, api_get_user_id(), api_get_session_id(),
/** * Course available settings variables see c_course_setting table * @param AppPlugin $appPlugin * @return array */ public static function getCourseSettingVariables(AppPlugin $appPlugin) { $pluginCourseSettings = $appPlugin->getAllPluginCourseSettings(); $courseSettings = array('allow_learning_path_theme', 'allow_open_chat_window', 'allow_public_certificates', 'allow_user_edit_agenda', 'allow_user_edit_announcement', 'allow_user_image_forum', 'allow_user_view_user_list', 'course_theme', 'display_info_advance_inside_homecourse', 'documents_default_visibility', 'email_alert_manager_on_new_doc', 'email_alert_manager_on_new_quiz', 'email_alert_on_new_doc_dropbox', 'email_alert_students_on_new_homework', 'email_alert_to_teacher_on_new_user_in_course', 'enable_lp_auto_launch', 'pdf_export_watermark_text', 'show_system_folders'); $allowLPReturnLink = api_get_setting('course.allow_lp_return_link'); if ($allowLPReturnLink === 'true') { $courseSettings[] = 'lp_return_link'; } if (!empty($pluginCourseSettings)) { $courseSettings = array_merge($courseSettings, $pluginCourseSettings); } return $courseSettings; }
/** * Fills the course database with some required content and example content. * @param int Course (int) ID * @param string Course directory name (e.g. 'ABC') * @param string Language used for content (e.g. 'spanish') * @param bool Whether to fill the course with example content * @return bool False on error, true otherwise * @version 1.2 * @assert (null, '', '', null) === false * @assert (1, 'ABC', null, null) === false * @assert (1, 'TEST', 'spanish', true) === true */ public static function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null) { if (is_null($fill_with_exemplary_content)) { $fill_with_exemplary_content = api_get_setting('course.example_material_course_creation') != 'false'; } $course_id = intval($course_id); if (empty($course_id)) { return false; } $entityManager = Database::getManager(); $course = $entityManager->getRepository('ChamiloCoreBundle:Course')->find($course_id); $tools = array(); $settingsManager = CourseManager::getCourseSettingsManager(); $settingsManager->setCourse($course); $toolList = CourseManager::getToolList(); $toolList = $toolList->getTools(); /** @var Chamilo\CourseBundle\Tool\BaseTool $tool */ foreach ($toolList as $tool) { $visibility = self::string2binary(api_get_setting_in_list('course.active_tools_on_create', $tool->getName())); $toolObject = new CTool(); $toolObject->setName($tool->getName())->setCategory($tool->getCategory())->setLink($tool->getLink())->setImage($tool->getImage())->setVisibility($visibility)->setAdmin(0)->setTarget($tool->getTarget()); $tools[] = $toolObject; $settings = $settingsManager->loadSettings($tool->getName()); $settingsManager->saveSettings($tool->getName(), $settings); } $course->setTools($tools); $entityManager->persist($course); $entityManager->flush($course); $courseInfo = api_get_course_info_by_id($course_id); $now = api_get_utc_datetime(time()); $tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST); $TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO); $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA); $TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT); $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $TABLETOOLLINK = Database::get_course_table(TABLE_LINK); $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST); $TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION); $TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER); $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); $TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); $TABLEFORUMS = Database::get_course_table(TABLE_FORUM); $TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD); $TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST); $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $visible_for_all = 1; $visible_for_course_admin = 0; $visible_for_platform_admin = 2; /* Course tools */ $alert = api_get_setting('exercise.email_alert_manager_on_new_quiz'); if ($alert === 'true') { $defaultEmailExerciseAlert = 1; } else { $defaultEmailExerciseAlert = 0; } /* course_setting table (courseinfo tool) */ $settings = ['email_alert_manager_on_new_doc' => ['default' => 0, 'category' => 'work'], 'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], 'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], 'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], 'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], 'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], 'course_theme' => ['default' => '', 'category' => 'theme'], 'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], 'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], 'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'], 'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'], 'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'], 'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'], 'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'], 'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'], 'allow_public_certificates' => ['default' => api_get_setting('course.allow_public_certificates') === 'true' ? 1 : '', 'category' => 'certificates'], 'documents_default_visibility' => ['default' => 'visible', 'category' => 'document']]; /*$counter = 1; foreach ($settings as $variable => $setting) { Database::query( "INSERT INTO $TABLESETTING (id, c_id, variable, value, category) VALUES ($counter, $course_id, '".$variable."', '".$setting['default']."', '".$setting['category']."')" ); $counter++; }*/ /* Course homepage tools for platform admin only */ /* Group tool */ Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id, title , description, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)\n VALUES ({$course_id}, '2', '" . self::lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');"); /* Example Material */ $language_interface = !empty($language_interface) ? $language_interface : api_get_setting('language.platform_language'); // Example material should be in the same language as the course is. $language_interface_original = $language_interface; $now = api_get_utc_datetime(); $files = [['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0], ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0]]; $counter = 1; foreach ($files as $file) { self::insertDocument($course_id, $counter, $file); $counter++; } $sys_course_path = api_get_path(SYS_COURSE_PATH); $perm = api_get_permissions_for_new_directories(); $perm_file = api_get_permissions_for_new_files(); $chat_path = $sys_course_path . $course_repository . '/document/chat_files'; if (!is_dir($chat_path)) { @mkdir($chat_path, api_get_permissions_for_new_directories()); } /* Documents */ if ($fill_with_exemplary_content) { $files = [['path' => '/images', 'title' => get_lang('Images'), 'filetype' => 'folder', 'size' => 0], ['path' => '/images/gallery', 'title' => get_lang('DefaultCourseImages'), 'filetype' => 'folder', 'size' => 0], ['path' => '/audio', 'title' => get_lang('Audio'), 'filetype' => 'folder', 'size' => 0], ['path' => '/flash', 'title' => get_lang('Flash'), 'filetype' => 'folder', 'size' => 0], ['path' => '/video', 'title' => get_lang('Video'), 'filetype' => 'folder', 'size' => 0], ['path' => '/certificates', 'title' => get_lang('Certificates'), 'filetype' => 'folder', 'size' => 0]]; foreach ($files as $file) { self::insertDocument($course_id, $counter, $file); $counter++; } // FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES $folders_to_copy_from_default_course = array('images', 'audio', 'flash', 'video', 'certificates'); $default_course_path = api_get_path(SYS_CODE_PATH) . 'default_course_document/'; $default_document_array = array(); foreach ($folders_to_copy_from_default_course as $folder) { $default_course_folder_path = $default_course_path . $folder . '/'; $files = self::browse_folders($default_course_folder_path, array(), $folder); $sorted_array = self::sort_pictures($files, 'dir'); $sorted_array = array_merge($sorted_array, self::sort_pictures($files, 'file')); $default_document_array[$folder] = $sorted_array; } //Light protection (adding index.html in every document folder) $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>"; $example_cert_id = 0; if (is_array($default_document_array) && count($default_document_array) > 0) { foreach ($default_document_array as $media_type => $array_media) { $path_documents = "/{$media_type}/"; //hack until feature #5242 is implemented if ($media_type == 'images') { $media_type = 'images/gallery'; $images_folder = $sys_course_path . $course_repository . "/document/images/"; if (!is_dir($images_folder)) { //Creating index.html mkdir($images_folder, $perm); $fd = fopen($images_folder . 'index.html', 'w'); fwrite($fd, $htmlpage); @chmod($images_folder . 'index.html', $perm_file); } } $course_documents_folder = $sys_course_path . $course_repository . "/document/{$media_type}/"; $default_course_path = api_get_path(SYS_CODE_PATH) . 'default_course_document' . $path_documents; if (!is_dir($course_documents_folder)) { // Creating index.html mkdir($course_documents_folder, $perm); $fd = fopen($course_documents_folder . 'index.html', 'w'); fwrite($fd, $htmlpage); @chmod($course_documents_folder . 'index.html', $perm_file); } if (is_array($array_media) && count($array_media) > 0) { foreach ($array_media as $key => $value) { if (isset($value['dir']) && !empty($value['dir'])) { if (!is_dir($course_documents_folder . $value['dir'])) { //Creating folder mkdir($course_documents_folder . $value['dir'], $perm); //Creating index.html (for light protection) $index_html = $course_documents_folder . $value['dir'] . '/index.html'; $fd = fopen($index_html, 'w'); fwrite($fd, $htmlpage); @chmod($index_html, $perm_file); //Inserting folder in the DB $folder_path = substr($value['dir'], 0, strlen($value['dir']) - 1); $temp = explode('/', $folder_path); $title = $temp[count($temp) - 1]; //hack until feature #5242 is implemented if ($title == 'gallery') { $title = get_lang('DefaultCourseImages'); } if ($media_type == 'images/gallery') { $folder_path = 'gallery/' . $folder_path; } Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size)\n VALUES ({$course_id},'{$path_documents}" . $folder_path . "','" . $title . "','folder','0')"); $image_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id},'document',1,'{$now}','{$now}',{$image_id},'DocumentAdded',1,NULL,NULL,0)"); } } if (isset($value['file']) && !empty($value['file'])) { if (!file_exists($course_documents_folder . $value['file'])) { //Copying file copy($default_course_path . $value['file'], $course_documents_folder . $value['file']); chmod($course_documents_folder . $value['file'], $perm_file); //echo $default_course_path.$value['file']; echo ' - '; echo $course_documents_folder.$value['file']; echo '<br />'; $temp = explode('/', $value['file']); $file_size = filesize($course_documents_folder . $value['file']); //hack until feature #5242 is implemented if ($media_type == 'images/gallery') { $value["file"] = 'gallery/' . $value["file"]; } //Inserting file in the DB Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size)\n VALUES ({$course_id},'{$path_documents}" . $value["file"] . "','" . $temp[count($temp) - 1] . "','file','{$file_size}')"); $image_id = Database::insert_id(); if ($image_id) { $sql = "UPDATE {$TABLETOOLDOCUMENT} SET id = iid WHERE iid = {$image_id}"; Database::query($sql); if ($path_documents . $value['file'] == '/certificates/default.html') { $example_cert_id = $image_id; } Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id},'document',1,'{$now}','{$now}',{$image_id},'DocumentAdded',1,NULL,NULL,1)"); $docId = Database::insert_id(); if ($docId) { $sql = "UPDATE {$TABLEITEMPROPERTY} SET id = iid WHERE iid = {$docId}"; Database::query($sql); } } } } } } } } $agenda = new Agenda(); $agenda->setType('course'); $agenda->set_course($courseInfo); $agenda->addEvent($now, $now, 0, get_lang('AgendaCreationTitle'), get_lang('AgendaCreationContenu')); /* Links tool */ $link = new Link(); $link->setCourse($courseInfo); $links = [['c_id' => $course_id, 'url' => 'http://www.google.com', 'title' => 'Google', 'description' => get_lang('Google'), 'category_id' => 0, 'on_homepage' => 0, 'target' => '_self', 'session_id' => 0], ['c_id' => $course_id, 'url' => 'http://www.wikipedia.org', 'title' => 'Wikipedia', 'description' => get_lang('Wikipedia'), 'category_id' => 0, 'on_homepage' => 0, 'target' => '_self', 'session_id' => 0]]; foreach ($links as $params) { $link->save($params); } /* Announcement tool */ AnnouncementManager::add_announcement(get_lang('AnnouncementExampleTitle'), get_lang('AnnouncementEx'), ['everyone' => 'everyone'], null, null, $now); $manager = Database::getManager(); /* Introduction text */ $intro_text = '<p style="text-align: center;"> <img src="' . api_get_path(REL_CODE_PATH) . 'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" /> <h2>' . self::lang2db(get_lang('IntroductionText')) . '</h2> </p>'; $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro(); $toolIntro->setCId($course_id)->setId(TOOL_COURSE_HOMEPAGE)->setSessionId(0)->setIntroText($intro_text); $manager->persist($toolIntro); $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro(); $toolIntro->setCId($course_id)->setId(TOOL_STUDENTPUBLICATION)->setSessionId(0)->setIntroText(get_lang('IntroductionTwo')); $manager->persist($toolIntro); $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro(); $toolIntro->setCId($course_id)->setId(TOOL_WIKI)->setSessionId(0)->setIntroText(get_lang('IntroductionWiki')); $manager->persist($toolIntro); $manager->flush(); /* Exercise tool */ $exercise = new Exercise($course_id); $exercise->exercise = get_lang('ExerciceEx'); $html = '<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="110" valign="top" align="left"> <img src="' . api_get_path(WEB_CODE_PATH) . 'default_course_document/images/mr_dokeos/thinking.jpg"> </td> <td valign="top" align="left">' . get_lang('Antique') . '</td></tr> </table>'; $exercise->type = 1; $exercise->setRandom(0); $exercise->active = 1; $exercise->results_disabled = 0; $exercise->description = $html; $exercise->save(); $exercise_id = $exercise->id; $question = new MultipleAnswer(); $question->question = get_lang('SocraticIrony'); $question->description = get_lang('ManyAnswers'); $question->weighting = 10; $question->position = 1; $question->course = $courseInfo; $question->save($exercise_id); $questionId = $question->id; $answer = new Answer($questionId, $courseInfo['real_id']); $answer->createAnswer(get_lang('Ridiculise'), 0, get_lang('NoPsychology'), -5, 1); $answer->createAnswer(get_lang('AdmitError'), 0, get_lang('NoSeduction'), -5, 2); $answer->createAnswer(get_lang('Force'), 1, get_lang('Indeed'), 5, 3); $answer->createAnswer(get_lang('Contradiction'), 1, get_lang('NotFalse'), 5, 4); $answer->save(); /* Forum tool */ require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php'; $params = ['forum_category_title' => get_lang('ExampleForumCategory'), 'forum_category_comment' => '']; $forumCategoryId = store_forumcategory($params, $courseInfo, false); $params = ['forum_category' => $forumCategoryId, 'forum_title' => get_lang('ExampleForum'), 'forum_comment' => '', 'default_view_type_group' => ['default_view_type' => 'flat']]; $forumId = store_forum($params, $courseInfo, true); $forumInfo = get_forum_information($forumId, $courseInfo['real_id']); $params = ['post_title' => get_lang('ExampleThread'), 'forum_id' => $forumId, 'post_text' => get_lang('ExampleThreadContent'), 'calification_notebook_title' => '', 'numeric_calification' => '', 'weight_calification' => '', 'forum_category' => $forumCategoryId, 'thread_peer_qualify' => 0]; store_thread($forumInfo, $params, $courseInfo, false); /* Gradebook tool */ $course_code = $courseInfo['code']; // father gradebook Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id)\n VALUES ('{$course_code}','',1,'{$course_code}',0,100,0,75,NULL,{$example_cert_id})"); $gbid = Database::insert_id(); Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id)\n VALUES ('{$course_code}','',1,'{$course_code}',{$gbid},100,1,75,NULL,{$example_cert_id})"); $gbid = Database::insert_id(); Database::query("INSERT INTO {$TABLEGRADEBOOKLINK} (type, ref_id, user_id, course_code, category_id, created_at, weight, visible, locked)\n VALUES (1,{$exercise_id},1,'{$course_code}',{$gbid},'{$now}',100,1,0)"); } //Installing plugins in course $app_plugin = new AppPlugin(); $app_plugin->install_course_plugins($course_id); $language_interface = $language_interface_original; return true; }
/** * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully) * Sender name and email can be specified, if not specified * name and email of the platform admin are used * * @author Bert Vanderkimpen ICT&O UGent * @author Yannick Warnier <*****@*****.**> * * @param string name of recipient * @param string email of recipient * @param string email subject * @param string email body * @param string sender name * @param string sender e-mail * @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array data file (path and filename) * @param array data to attach a file (optional) * @param bool True for attaching a embedded file inside content html (optional) * @return returns true if mail was sent * @see class.phpmailer.php */ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $senderName = '', $senderEmail = '', $extra_headers = array(), $data_file = array(), $embedded_image = false, $additionalParameters = array()) { // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultName; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail; $link = isset($additionalParameters['link']) ? $additionalParameters['link'] : ''; $swiftMessage = \Swift_Message::newInstance()->setSubject($subject)->setFrom($senderEmail, $senderName)->setTo($recipient_email, $recipient_name)->setBody(Container::getTemplating()->render('ChamiloCoreBundle:default/mail:mail.html.twig', array('content' => $message, 'link' => $link)), 'text/html'); if (!empty($additionalParameters)) { $plugin = new AppPlugin(); $smsPlugin = $plugin->getSMSPluginLibrary(); if ($smsPlugin) { $smsPlugin->send($additionalParameters); } } Container::getMailer()->send($swiftMessage); return 1; global $platform_email; $mail = new PHPMailer(); $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; $mail->CharSet = $platform_email['SMTP_CHARSET']; // Stay far below SMTP protocol 980 chars limit. $mail->WordWrap = 200; if ($platform_email['SMTP_AUTH']) { $mail->SMTPAuth = 1; $mail->Username = $platform_email['SMTP_USER']; $mail->Password = $platform_email['SMTP_PASS']; } // 5 = low, 1 = high $mail->Priority = 3; $mail->SMTPKeepAlive = true; // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // Error to admin. $mail->AddCustomHeader('Errors-To: ' . $defaultEmail); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultName; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail; // Reply to first if (isset($extra_headers['reply_to'])) { $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); $mail->Sender = $extra_headers['reply_to']['mail']; unset($extra_headers['reply_to']); } //If the SMTP configuration only accept one sender if ($platform_email['SMTP_UNIQUE_SENDER']) { $senderName = $platform_email['SMTP_FROM_NAME']; $senderEmail = $platform_email['SMTP_FROM_EMAIL']; } $mail->SetFrom($senderEmail, $senderName); $mail->Subject = $subject; $mail->AltBody = strip_tags(str_replace('<br />', "\n", api_html_entity_decode($message))); // Send embedded image. if ($embedded_image) { // Get all images html inside content. preg_match_all("/<img\\s+.*?src=[\"\\']?([^\"\\' >]*)[\"\\']?[^>]*>/i", $message, $m); // Prepare new tag images. $new_images_html = array(); $i = 1; if (!empty($m[1])) { foreach ($m[1] as $image_path) { $real_path = realpath($image_path); $filename = basename($image_path); $image_cid = $filename . '_' . $i; $encoding = 'base64'; $image_type = mime_content_type($real_path); $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); $new_images_html[] = '<img src="cid:' . $image_cid . '" />'; $i++; } } // Replace origin image for new embedded image html. $x = 0; if (!empty($m[0])) { foreach ($m[0] as $orig_img) { $message = str_replace($orig_img, $new_images_html[$x], $message); $x++; } } } $message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message); $mailView = new Template(null, false, false, false, false, false, false); $mailView->assign('content', $message); $link = $additionalParameters['link']; $mailView->assign('link', $link); $layout = $mailView->get_template('mail/mail.tpl'); $mail->Body = $mailView->fetch($layout); // Attachment ... if (!empty($data_file)) { $mail->AddAttachment($data_file['path'], $data_file['filename']); } // Only valid addresses are accepted. if (is_array($recipient_email)) { foreach ($recipient_email as $dest) { if (api_valid_email($dest)) { $mail->AddAddress($dest, $recipient_name); } } } else { if (api_valid_email($recipient_email)) { $mail->AddAddress($recipient_email, $recipient_name); } else { return 0; } } if (is_array($extra_headers) && count($extra_headers) > 0) { foreach ($extra_headers as $key => $value) { switch (strtolower($key)) { case 'encoding': case 'content-transfer-encoding': $mail->Encoding = $value; break; case 'charset': $mail->Charset = $value; break; case 'contenttype': case 'content-type': $mail->ContentType = $value; break; default: $mail->AddCustomHeader($key . ':' . $value); break; } } } else { if (!empty($extra_headers)) { $mail->AddCustomHeader($extra_headers); } } // WordWrap the html body (phpMailer only fixes AltBody) FS#2988 $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap); // Send the mail message. if (!$mail->Send()) { error_log('ERROR: mail not sent to ' . $recipient_name . ' (' . $recipient_email . ') because of ' . $mail->ErrorInfo . '<br />'); return 0; } if (!empty($additionalParameters)) { $plugin = new AppPlugin(); $smsPlugin = $plugin->getSMSPluginLibrary(); if ($smsPlugin) { $smsPlugin->send($additionalParameters); } } // Clear all the addresses. $mail->ClearAddresses(); return 1; }
/** * Displays the tools of a certain category. * @param array $all_tools_list List of tools as returned by get_tools_category() * @param bool $rows * * @return void */ public static function show_tools_category($all_tools_list, $rows = false) { $_user = api_get_user_info(); $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($all_tools_list) && count($all_tools_list) > 0) { foreach ($all_tools_list as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $all_tools_list[$key]; } $all_tools_list = $my_temp_tool_array; } else { $all_tools_list = array(); } } $web_code_path = api_get_path(WEB_CODE_PATH); $session_id = api_get_session_id(); $is_platform_admin = api_is_platform_admin(); if ($session_id == 0) { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); } else { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); } $i = 0; $items = array(); $app_plugin = new AppPlugin(); if (isset($all_tools_list)) { $lnk = ''; foreach ($all_tools_list as &$tool) { $item = array(); $studentview = false; $tool['original_link'] = $tool['link']; if ($tool['image'] == 'scormbuilder.gif') { // check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (api_is_allowed_to_edit(null, true)) { $studentview = true; } if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) { continue; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; if ($is_allowed_to_edit) { if (empty($session_id)) { if (isset($tool['id'])) { if ($tool['visibility'] == '1' && $toolAdmin != '1') { $link['name'] = Display::return_icon('visible.png', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'hide=yes'; $lnk[] = $link; } if ($tool['visibility'] == '0' && $toolAdmin != '1') { $link['name'] = Display::return_icon('invisible.png', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'restore=yes'; $lnk[] = $link; } } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($toolAdmin != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . api_get_self() . '?' . api_get_cidreq() . '&id=' . $tool['id'] . '&' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= ''; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if ($tool['visibility'] == '0' && $toolAdmin != '1' && !isset($tool['original_link'])) { $class = 'invisible'; $info = pathinfo($tool['image']); $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); $toolId = isset($tool["id"]) ? $tool["id"] : null; //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->getPluginInfo($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } if (!file_exists(api_get_path(SYS_CODE_PATH) . 'img/' . $tool['image']) && !file_exists(api_get_path(SYS_CODE_PATH) . 'img/icons/22/' . $tool['image'])) { $tool['image'] = 'plugins.png'; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } $icon = Display::return_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); /*if (!empty($tool['custom_icon'])) { $image = self::getCustomWebIconPath().$tool['custom_icon']; $icon = Display::img( $image, $tool['description'], array( 'class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'] ) ); }*/ // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], !empty($_user['status']) ? $_user['status'] : ''); if ($studentview) { $tool_link_params['href'] .= '&isStudentView=true'; } $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; $i++; } // end of foreach } $i = 0; $html = ''; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; $html .= '<div class="col-xs-6 col-md-3 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null; if (isset($item['tool']['custom_image'])) { $original_image = Display::img($item['tool']['custom_image'], $item['name'], array('id' => 'toolimage_' . $toolId)); } elseif (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) { $customIcon = $item['tool']['custom_icon']; if ($item['tool']['visibility'] == '0') { $fileInfo = pathinfo($item['tool']['custom_icon']); $customIcon = self::getDisableIcon($item['tool']['custom_icon']); } $original_image = Display::img(self::getCustomWebIconPath() . $customIcon, $item['name'], array('id' => 'toolimage_' . $toolId)); } else { $original_image = Display::return_icon($image, $item['name'], array('id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); } $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; break; case 'activity': $html .= '<div class="offset2 col-md-4 course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</div>'; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return $html; }
/** * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully) * Sender name and email can be specified, if not specified * name and email of the platform admin are used * * @author Bert Vanderkimpen ICT&O UGent * @author Yannick Warnier <*****@*****.**> * * @param string name of recipient * @param string email of recipient * @param string email subject * @param string email body * @param string sender name * @param string sender e-mail * @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array data file (path and filename) * @param array data to attach a file (optional) * @param bool True for attaching a embedded file inside content html (optional) * @return returns true if mail was sent * @see class.phpmailer.php */ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $senderName = '', $senderEmail = '', $extra_headers = array(), $data_file = array(), $embedded_image = false, $additionalParameters = array()) { // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultName; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail; $link = isset($additionalParameters['link']) ? $additionalParameters['link'] : ''; $swiftMessage = \Swift_Message::newInstance()->setSubject($subject)->setFrom($senderEmail, $senderName)->setTo($recipient_email, $recipient_name)->setBody(Container::getTemplating()->render('ChamiloCoreBundle:default/mail:mail.html.twig', array('content' => $message, 'link' => $link)), 'text/html'); if (!empty($additionalParameters)) { $plugin = new AppPlugin(); $smsPlugin = $plugin->getSMSPluginLibrary(); if ($smsPlugin) { $smsPlugin->send($additionalParameters); } } Container::getMailer()->send($swiftMessage); return 1; }
/** * This function allows easy activating and inactivating of plugins * @author Patrick Cool <*****@*****.**>, Ghent University */ function store_plugins() { $appPlugin = new AppPlugin(); // Get a list of all current 'Plugins' settings $plugin_list = $appPlugin->read_plugins_from_path(); $installed_plugins = array(); foreach ($plugin_list as $plugin) { if (isset($_POST['plugin_' . $plugin])) { $appPlugin->install($plugin); $installed_plugins[] = $plugin; } } if (!empty($installed_plugins)) { $remove_plugins = array_diff($plugin_list, $installed_plugins); } else { $remove_plugins = $plugin_list; } foreach ($remove_plugins as $plugin) { $appPlugin->uninstall($plugin); } }
/** * Fills the course database with some required content and example content. */ public static function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null) { if (is_null($fill_with_exemplary_content)) { $fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false'; } $course_id = intval($course_id); if (empty($course_id)) { return false; } $now = api_get_utc_datetime(time()); $toolTable = Database::get_course_table(TABLE_TOOL_LIST); $TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO); $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA); $TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT); $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $TABLETOOLLINK = Database::get_course_table(TABLE_LINK); $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST); $TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION); $TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER); $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); $TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); $TABLEFORUMS = Database::get_course_table(TABLE_FORUM); $TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD); $TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST); $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $visible_for_all = 1; $visible_for_course_admin = 0; $visible_for_platform_admin = 2; // Move this in a doctrine listener $toolList = self::getToolList(); $toolList = $toolList->getTools(); /** @var Course $course */ $entityManager = Database::getManager(); $course = $entityManager->getRepository('ChamiloCoreBundle:Course')->find($course_id); // @todo move in a manager. /** @var Chamilo\CourseBundle\Tool\BaseTool $tool */ $tools = array(); $settingsManager = self::getCourseSettingsManager(); $settingsManager->setCourse($course); foreach ($toolList as $tool) { $visibility = Text::string2binary(api_get_setting('course.course_create_active_tools', $tool->getName())); $toolObject = new CTool(); $toolObject->setName($tool->getName())->setCategory($tool->getCategory())->setLink($tool->getLink())->setImage($tool->getImage())->setVisibility($visibility)->setAdmin(0)->setTarget($tool->getTarget()); $tools[] = $toolObject; $settings = $settingsManager->loadSettings($tool->getName()); $settingsManager->saveSettings($tool->getName(), $settings); } $course->setTools($tools); $entityManager->persist($course); $entityManager->flush($course); /* Course tools */ /*if (api_get_setting('service_visio', 'active') == 'true') { $mycheck = api_get_setting('service_visio', 'visio_host'); if (!empty($mycheck)) { //Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '" . TOOL_VISIO_CONFERENCE . "','conference/index.php?type=conference','visio_meeting.gif','1','0','squaregrey.gif','NO','_self','interaction','0', '', '')"); //Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '" . TOOL_VISIO_CLASSROOM . "','conference/index.php?type=classroom','visio.gif','1','0','squaregrey.gif','NO','_self','authoring','0', '', '')"); } }*/ /*if (api_get_setting('search_enabled') == 'true') { //Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '" . TOOL_SEARCH. "','search/','info.gif','".Text::string2binary(api_get_setting('course_create_active_tools', 'enable_search')) . "','0','search.gif','NO','_self','authoring','0', '', '')"); }*/ // Blogs (Kevin Van Den Haute :: kevin@develop-it.be) /*$sql = "INSERT INTO $toolTable VALUES ($course_id, NULL,'" . TOOL_BLOGS . "','blog/blog_admin.php','blog_admin.gif','" . Text::string2binary(api_get_setting('course_create_active_tools', 'blogs')) . "','1','squaregrey.gif','NO','_self','admin','0', '', '')"; Database::query($sql);*/ /* Course homepage tools for course admin only */ /* Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '".TOOL_TRACKING . "','tracking/courseLog.php','statistics.gif','$visible_for_course_admin','1','', 'NO','_self','admin','0', '', '')"); Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '".TOOL_COURSE_SETTING . "','course_info/infocours.php','reference.gif','$visible_for_course_admin','1','', 'NO','_self','admin','0', '', '')"); Database::query("INSERT INTO $toolTable VALUES ($course_id, NULL, '".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible_for_course_admin','1','','NO','_self', 'admin','0', '', '')");*/ /* Course_setting table (courseinfo tool) */ /*Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_manager_on_new_doc',0,'work')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_on_new_doc_dropbox',0,'dropbox')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_edit_agenda',0,'agenda')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_edit_announcement',0,'announcement')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_manager_on_new_quiz',1,'quiz')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_image_forum',1,'forum')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'course_theme','','theme')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_learning_path_theme','1','theme')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_open_chat_window',1,'chat')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_to_teacher_on_new_user_in_course',0,'registration')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_view_user_list',1,'user')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'display_info_advance_inside_homecourse',1,'thematic_advance')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_students_on_new_homework',0,'work')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'enable_lp_auto_launch',0,'learning_path')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'pdf_export_watermark_text','','learning_path')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_public_certificates','','certificates')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_fast_exercise_edition', 0 ,'exercise')"); Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'enable_exercise_auto_launch', 0 ,'exercise')");*/ /* Course homepage tools for platform admin only */ /* Group tool */ Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id , title , description , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order )\n VALUES ({$course_id}, '2', '" . Database::escape_string(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');"); /* Example Material */ $language_interface = Container::getTranslator()->getLocale(); // Example material should be in the same language as the course is. $language_interface_original = $language_interface; $language_interface = $language; //Share folder Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/shared_folder','" . get_lang('UserFolders') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); //Chat folder Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/chat_files','" . get_lang('ChatFiles') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); $sys_course_path = api_get_path(SYS_COURSE_PATH); $perm = api_get_permissions_for_new_directories(); $perm_file = api_get_permissions_for_new_files(); $chat_path = $sys_course_path . $course_repository . '/document/chat_files'; if (!is_dir($chat_path)) { @mkdir($chat_path, api_get_permissions_for_new_directories()); } /* Documents */ if ($fill_with_exemplary_content) { Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id,path,title,filetype,size) VALUES ({$course_id},'/images','" . get_lang('Images') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/images/gallery','" . get_lang('DefaultCourseImages') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/audio','" . get_lang('Audio') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/flash','" . get_lang('Flash') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/video','" . get_lang('Video') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/certificates','" . get_lang('Certificates') . "','folder','0')"); $example_doc_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)"); // FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES $folders_to_copy_from_default_course = array('images', 'audio', 'flash', 'video', 'certificates'); $default_course_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH); $default_document_array = array(); foreach ($folders_to_copy_from_default_course as $folder) { $default_course_folder_path = $default_course_path . $folder . '/'; $files = self::browse_folders($default_course_folder_path, array(), $folder); $sorted_array = self::sort_pictures($files, 'dir'); $sorted_array = array_merge($sorted_array, self::sort_pictures($files, 'file')); $default_document_array[$folder] = $sorted_array; } //Light protection (adding index.html in every document folder) $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>"; $example_cert_id = 0; if (is_array($default_document_array) && count($default_document_array) > 0) { foreach ($default_document_array as $media_type => $array_media) { $path_documents = "/{$media_type}/"; //hack until feature #5242 is implemented if ($media_type == 'images') { $media_type = 'images/gallery'; $images_folder = $sys_course_path . $course_repository . "/document/images/"; if (!is_dir($images_folder)) { //Creating index.html mkdir($images_folder, $perm); $fd = fopen($images_folder . 'index.html', 'w'); fwrite($fd, $htmlpage); @chmod($images_folder . 'index.html', $perm_file); } } $course_documents_folder = $sys_course_path . $course_repository . "/document/{$media_type}/"; $default_course_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH) . $path_documents; //echo 'try '.$course_documents_folder; echo '<br />'; if (!is_dir($course_documents_folder)) { //Creating index.html mkdir($course_documents_folder, $perm); $fd = fopen($course_documents_folder . 'index.html', 'w'); fwrite($fd, $htmlpage); @chmod($course_documents_folder . 'index.html', $perm_file); } if (is_array($array_media) && count($array_media) > 0) { foreach ($array_media as $key => $value) { if (isset($value['dir']) && !empty($value['dir'])) { if (!is_dir($course_documents_folder . $value['dir'])) { //Creating folder mkdir($course_documents_folder . $value['dir'], $perm); //Creating index.html (for light protection) $index_html = $course_documents_folder . $value['dir'] . '/index.html'; $fd = fopen($index_html, 'w'); fwrite($fd, $htmlpage); @chmod($index_html, $perm_file); //Inserting folder in the DB $folder_path = substr($value['dir'], 0, strlen($value['dir']) - 1); $temp = explode('/', $folder_path); $title = $temp[count($temp) - 1]; //hack until feature #5242 is implemented if ($title == 'gallery') { $title = get_lang('DefaultCourseImages'); } if ($media_type == 'images/gallery') { $folder_path = 'gallery/' . $folder_path; } Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'{$path_documents}" . $folder_path . "','" . $title . "','folder','0')"); $image_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$image_id},'DocumentAdded',1,0,NULL,0)"); } } if (isset($value['file']) && !empty($value['file'])) { if (!file_exists($course_documents_folder . $value['file'])) { //Copying file copy($default_course_path . $value['file'], $course_documents_folder . $value['file']); chmod($course_documents_folder . $value['file'], $perm_file); //echo $default_course_path.$value['file']; echo ' - '; echo $course_documents_folder.$value['file']; echo '<br />'; $temp = explode('/', $value['file']); $file_size = filesize($course_documents_folder . $value['file']); //hack until feature #5242 is implemented if ($media_type == 'images/gallery') { $value["file"] = 'gallery/' . $value["file"]; } //Inserting file in the DB Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'{$path_documents}" . $value["file"] . "','" . $temp[count($temp) - 1] . "','file','{$file_size}')"); $image_id = Database::insert_id(); if ($path_documents . $value['file'] == '/certificates/default.html') { $example_cert_id = $image_id; } Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$image_id},'DocumentAdded',1,0,NULL,1)"); } } } } } } /* Agenda tool */ Database::query("INSERT INTO {$TABLETOOLAGENDA} VALUES ({$course_id}, NULL, '" . Database::escape_string(get_lang('AgendaCreationTitle')) . "', '" . Database::escape_string(get_lang('AgendaCreationContenu')) . "', now(), now(), NULL, 0, 0)"); // We need to add the item properties too! $insert_id = Database::insert_id(); $sql = "INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id}, '" . TOOL_CALENDAR_EVENT . "',1,NOW(),NOW(),{$insert_id},'AgendaAdded',1,0,NULL,1)"; Database::query($sql); /* Links tool */ $add_google_link_sql = "INSERT INTO {$TABLETOOLLINK} (c_id, url, title, description, category_id, display_order, on_homepage, target)\n VALUES ({$course_id}, 'http://www.google.com','Google','" . Database::escape_string(get_lang('Google')) . "','0','0','0','_self')"; Database::query($add_google_link_sql); // We need to add the item properties too! $insert_id = Database::insert_id(); $sql = "INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id}, '" . TOOL_LINK . "',1,NOW(),NOW(),{$insert_id},'LinkAdded',1,0,NULL,1)"; Database::query($sql); $add_wikipedia_link_sql = "INSERT INTO {$TABLETOOLLINK} (c_id, url, title, description, category_id, display_order, on_homepage, target)\n VALUES ({$course_id}, 'http://www.wikipedia.org','Wikipedia','" . Database::escape_string(get_lang('Wikipedia')) . "','0','1','0','_self')"; Database::query($add_wikipedia_link_sql); // We need to add the item properties too! $insert_id = Database::insert_id(); $sql = "INSERT INTO {$TABLEITEMPROPERTY} (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_LINK . "',1,NOW(),NOW(),{$insert_id},'LinkAdded',1,0,NULL,1)"; Database::query($sql); /* Announcement tool */ $sql = "INSERT INTO {$TABLETOOLANNOUNCEMENTS} (c_id, title,content,end_date,display_order,email_sent)\n VALUES ({$course_id}, '" . Database::escape_string(get_lang('AnnouncementExampleTitle')) . "', '" . Database::escape_string(get_lang('AnnouncementEx')) . "', NOW(), '1','0')"; Database::query($sql); // We need to add the item properties too! $insert_id = Database::insert_id(); $sql = "INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id}, '" . TOOL_ANNOUNCEMENT . "',1,NOW(),NOW(),{$insert_id},'AnnouncementAdded',1,0,NULL,1)"; Database::query($sql); /* Introduction text */ $intro_text = '<p style="text-align: center;"> <img src="' . api_get_path(REL_CODE_PATH) . 'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" /> <h2>' . Database::escape_string(get_lang('IntroductionText')) . '</h2> </p>'; Database::query("INSERT INTO {$TABLEINTROS} VALUES ({$course_id}, '" . TOOL_COURSE_HOMEPAGE . "','" . $intro_text . "', 0)"); Database::query("INSERT INTO {$TABLEINTROS} VALUES ({$course_id}, '" . TOOL_STUDENTPUBLICATION . "','" . Database::escape_string(get_lang('IntroductionTwo')) . "', 0)"); // Wiki intro $intro_wiki = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="110" valign="top" align="left"></td><td valign="top" align="left">' . Database::escape_string(get_lang('IntroductionWiki')) . '</td></tr></table>'; Database::query("INSERT INTO {$TABLEINTROS} VALUES ({$course_id}, '" . TOOL_WIKI . "','" . $intro_wiki . "', 0)"); /* Exercise tool */ $html = Database::escape_string('<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td width="110" valign="top" align="left"> <img src="' . api_get_path(WEB_DEFAULT_COURSE_DOCUMENT_PATH) . 'images/mr_dokeos/thinking.jpg"></td><td valign="top" align="left">' . get_lang('Antique') . ' </td></tr></table>'); // Insert exercise Database::query('INSERT INTO ' . $TABLEQUIZ . ' (c_id, title, description, type, random, random_answers, active, results_disabled ) ' . ' VALUES (' . $course_id . ', "' . Database::escape_string(get_lang('ExerciceEx')) . '", "' . $html . '", "1", "0", "0", "1", "0")'); $exercise_id = Database::insert_id(); // Insert question Database::query("INSERT INTO {$TABLEQUIZQUESTIONLIST} (c_id, question, description, ponderation, position, type, picture, level)\n VALUES ( '.{$course_id}.', '" . Database::escape_string(get_lang('SocraticIrony')) . "', '" . Database::escape_string(get_lang('ManyAnswers')) . "', '10', '1', '2','',1)"); $questionId = Database::insert_id(); Database::query("INSERT INTO {$TABLEQUIZQUESTION} (c_id, question_id, exercice_id, question_order) VALUES ({$course_id},{$questionId} , {$exercise_id}, 1)"); // Insert answers Database::query("INSERT INTO {$TABLEQUIZANSWERSLIST} (c_id, question_id, answer, correct, comment, ponderation, position) VALUES ({$course_id}, '{$questionId}', '" . Database::escape_string(get_lang('Ridiculise')) . "', '0', '" . Database::escape_string(get_lang('NoPsychology')) . "', '-5', '1')"); Database::query("INSERT INTO {$TABLEQUIZANSWERSLIST} (c_id, question_id, answer, correct, comment, ponderation, position) VALUES ({$course_id}, '{$questionId}', '" . Database::escape_string(get_lang('AdmitError')) . "', '0', '" . Database::escape_string(get_lang('NoSeduction')) . "', '-5', '2')"); Database::query("INSERT INTO {$TABLEQUIZANSWERSLIST} (c_id, question_id, answer, correct, comment, ponderation, position) VALUES ({$course_id}, '{$questionId}', '" . Database::escape_string(get_lang('Force')) . "', '1', '" . Database::escape_string(get_lang('Indeed')) . "', '5', '3')"); Database::query("INSERT INTO {$TABLEQUIZANSWERSLIST} (c_id, question_id, answer, correct, comment, ponderation, position) VALUES ({$course_id}, '{$questionId}', '" . Database::escape_string(get_lang('Contradiction')) . "', '1', '" . Database::escape_string(get_lang('NotFalse')) . "', '5', '4')"); /* Forum tool */ Database::query("INSERT INTO {$TABLEFORUMCATEGORIES} VALUES ({$course_id}, 1,'" . Database::escape_string(get_lang('ExampleForumCategory')) . "', '', 1, 0, 0)"); $insert_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id}, 'forum_category',1,NOW(),NOW(),{$insert_id},'ForumCategoryAdded',1,0,NULL,1)"); Database::query("INSERT INTO {$TABLEFORUMS} (c_id, forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id )\n VALUES ({$course_id}, '" . Database::escape_string(get_lang('ExampleForum')) . "', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)"); $insert_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id}, '" . TOOL_FORUM . "', 1,NOW(),NOW(),{$insert_id},'ForumAdded',1,0,NULL,1)"); Database::query("INSERT INTO {$TABLEFORUMTHREADS} (c_id, thread_id, thread_title, forum_id, thread_replies, thread_poster_id, thread_poster_name, thread_views, thread_last_post, thread_date, locked, thread_qualify_max, session_id)\n VALUES ({$course_id}, 1, '" . Database::escape_string(get_lang('ExampleThread')) . "', 1, 0, 1, '', 0, 1, NOW(), 0, 10, 0)"); $insert_id = Database::insert_id(); Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id}, 'forum_thread',1,NOW(),NOW(),{$insert_id},'ForumThreadAdded',1,0,NULL,1)"); Database::query("INSERT INTO {$TABLEFORUMPOSTS} VALUES ({$course_id}, 1, '" . Database::escape_string(get_lang('ExampleThread')) . "', '" . Database::escape_string(get_lang('ExampleThreadContent')) . "', 1, 1, 1, '', NOW(), 0, 0, 1)"); /* Gradebook tool */ $course = api_get_course_info_by_id($course_id); $course_code = $course['code']; // father gradebook Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) VALUES ('{$course_code}','',1,'{$course_code}',0,100,0,NULL,NULL,{$example_cert_id})"); $gbid = Database::insert_id(); Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) VALUES ('{$course_code}','',1,'{$course_code}',{$gbid},100,1,75,NULL,{$example_cert_id})"); $gbid = Database::insert_id(); Database::query("INSERT INTO {$TABLEGRADEBOOKLINK} (type, ref_id, user_id, course_code, category_id, created_at, weight, visible, locked) VALUES (1,{$exercise_id},1,'{$course_code}',{$gbid},'{$now}',100,1,0)"); } //Installing plugins in course $app_plugin = new AppPlugin(); $app_plugin->install_course_plugins($course_id); $language_interface = $language_interface_original; return true; }
<?php /* For licensing terms, see /license.txt */ /** @author Julio Montoya <*****@*****.**> BeezNest 2012 * @package chamilo.admin */ // name of the language file that needs to be included $language_file = array('registration', 'admin'); $cidReset = true; require_once '../inc/global.inc.php'; // Access restrictions api_protect_admin_script(); $plugin_name = $_GET['name']; $plugin_obj = new AppPlugin(); $plugin_info = $plugin_obj->get_plugin_info($plugin_name, true); if (empty($plugin_info)) { api_not_allowed(); } $installed_plugins = $plugin_obj->get_installed_plugins(); if (!in_array($plugin_name, $installed_plugins)) { api_not_allowed(); } global $_configuration; $content = null; if (isset($plugin_info['settings_form'])) { $form = $plugin_info['settings_form']; if (isset($form)) { //We override the form attributes $attributes = array('action' => api_get_self() . '?name=' . $plugin_name, 'method' => 'POST'); $form->updateAttributes($attributes);
$group = array($form->createElement('radio', 'show_system_folders', null, get_lang('Yes'), 1), $form->createElement('radio', 'show_system_folders', null, get_lang('No'), 2)); $form->addGroup($group, '', array(get_lang("ShowSystemFolders")), ''); $form->addButtonSave(get_lang('SaveSettings'), 'submit_save'); $form->addElement('html', '</div></div>'); // Certificate settings if (api_get_setting('course.allow_public_certificates') == 'true') { $form->addElement('html', '<div><h3>' . Display::return_icon('certificate.png', Security::remove_XSS(get_lang('Certificates')), '', ICON_SIZE_SMALL) . ' ' . Security::remove_XSS(get_lang('Certificates')) . '</h3><div>'); $group = array(); $group[] = $form->createElement('radio', 'allow_public_certificates', get_lang('AllowPublicCertificates'), get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0); $form->addGroup($group, '', array(get_lang("AllowPublicCertificates")), ''); $form->addButtonSave(get_lang('SaveSettings'), 'submit_save'); $form->addElement('html', '</div></div>'); } // Plugin course settings $appPlugin = new AppPlugin(); $appPlugin->add_course_settings_form($form); // Get all the course information $all_course_information = CourseManager::get_course_information($_course['sysCode']); // Set the default values of the form $values = array(); $values['title'] = $_course['name']; $values['category_code'] = $_course['categoryCode']; $values['course_language'] = $_course['language']; $values['department_name'] = $_course['extLink']['name']; $values['department_url'] = $_course['extLink']['url']; $values['visibility'] = $_course['visibility']; $values['subscribe'] = $course_access_settings['subscribe']; $values['unsubscribe'] = $course_access_settings['unsubscribe']; $values['course_registration_password'] = $all_course_information['registration_code']; $values['legal'] = $all_course_information['legal'];
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DoNotDisplayAnyAdvance'), 0); $form->addGroup($group, '', array(get_lang("InfoAboutAdvanceInsideHomeCourse")), ''); $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"'); $form->addElement('html', '</div></div>'); // Certificate settings if (api_get_setting('allow_public_certificates') == 'true') { $form->addElement('html', '<div><h3>' . Display::return_icon('certificate.png', Security::remove_XSS(get_lang('Certificates')), '', ICON_SIZE_SMALL) . ' ' . Security::remove_XSS(get_lang('Certificates')) . '</h3><div>'); $group = array(); $group[] = $form->createElement('radio', 'allow_public_certificates', get_lang('AllowPublicCertificates'), get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0); $form->addGroup($group, '', array(get_lang("AllowPublicCertificates")), ''); $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"'); $form->addElement('html', '</div></div>'); } // Plugin course settings $app_plugin = new AppPlugin(); $app_plugin->add_course_settings_form($form); // Get all the course information $all_course_information = CourseManager::get_course_information($_course['sysCode']); // Set the default values of the form $values = array(); $values['title'] = $_course['name']; $values['category_code'] = $_course['categoryCode']; $values['course_language'] = $_course['language']; $values['department_name'] = $_course['extLink']['name']; $values['department_url'] = $_course['extLink']['url']; $values['visibility'] = $_course['visibility']; $values['subscribe'] = $course_access_settings['subscribe']; $values['unsubscribe'] = $course_access_settings['unsubscribe']; $values['course_registration_password'] = $all_course_information['registration_code']; $values['legal'] = $all_course_information['legal'];
<?php /* For licensing terms, see /license.txt */ /** * @author Julio Montoya <*****@*****.**> BeezNest 2012 * @author Angel Fernando Quiroz Campos <*****@*****.**> * @package chamilo.admin */ use ChamiloSession as Session; $cidReset = true; //require_once '../inc/global.inc.php'; // Access restrictions api_protect_admin_script(); $pluginName = $_GET['name']; $appPlugin = new AppPlugin(); $installedPlugins = $appPlugin->get_installed_plugins(); $pluginInfo = $appPlugin->getPluginInfo($pluginName, true); if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) { api_not_allowed(true); } $message = null; $content = null; $currentUrl = api_get_self() . "?name={$pluginName}"; if (isset($pluginInfo['settings_form'])) { $form = $pluginInfo['settings_form']; if (isset($form)) { //We override the form attributes $attributes = array('action' => $currentUrl, 'method' => 'POST'); $form->updateAttributes($attributes); $content = Display::page_header($pluginInfo['title']); $content .= $form->toHtml();
/** * Displays the tools of a certain category. * @param Symfony\Component\Routing\RouterInterface $urlGenerator * @param array List of tools as returned by get_tools_category() * @param bool rows * @return string */ public static function show_tools_category($urlGenerator, $toolList, $rows = false) { $rowDiv = '<div class="row">'; $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($toolList) && count($toolList) > 0) { foreach ($toolList as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $toolList[$key]; } $toolList = $my_temp_tool_array; } else { $toolList = array(); } } $courseInfo = api_get_course_info(); $web_code_path = api_get_path(WEB_CODE_PATH); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_platform_admin = api_is_platform_admin(); $session_id = api_get_session_id(); $items = array(); $app_plugin = new AppPlugin(); if (isset($toolList)) { $lnk = ''; foreach ($toolList as &$tool) { $item = array(); $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null; $tool['id'] = isset($tool['id']) ? $tool['id'] : null; $tool['target'] = isset($tool['target']) ? $tool['target'] : null; if (isset($tool['link_id'])) { $tool['original_link'] = api_get_path(WEB_CODE_PATH) . 'link/link_goto.php?link_id=' . $tool['link_id'] . '&' . api_get_cidreq(); $tool['link'] = $tool['original_link']; } else { $tool['original_link'] = $tool['link']; } // Re-writing URL for new tools $newTools = array(TOOL_CURRICULUM); $toolName = isset($tool['name']) ? $tool['name'] : null; if (in_array($toolName, $newTools)) { $tool['link'] = $courseInfo['course_web_public_url'] . $tool['name'] . '/'; } if ($tool['image'] == 'scormbuilder.gif') { // Check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) { continue; } if ($tool['name'] == 'course_description') { $tool['link'] = 'course_description/index.php'; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; if ($is_allowed_to_edit && !api_is_coach()) { if (empty($session_id)) { if ($tool['visibility'] == '1' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:hideIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:showIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($tool['admin'] != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= null; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if (!empty($tool['custom_icon'])) { $tool['image'] = self::getCustomIconPath($courseInfo) . $tool['custom_icon']; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $class = 'invisible'; $info = pathinfo($tool['image']); $dirName = null; if ($info['dirname'] != '.') { $dirName = $info['dirname'] . '/'; } $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $dirName . $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); $toolTip = $tool_name; if (!empty($tool['description'])) { $toolTip = $tool['description']; } $tool_link_params['data-original-title'] = $toolTip; $tool_link_params['data-toggle'] = 'tooltip'; //$tool_link_params['title'] = $toolTip; // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->get_plugin_info($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } if (!empty($tool['custom_icon'])) { //self::getCustomIconPath($courseInfo) $icon = Display::img($tool['image'], null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id'])); } else { $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png'; $icon = Display::return_icon($image, null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']), ICON_SIZE_BIG, false); } $userInfo = api_get_user_info(); $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null; // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], $userStatus); $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; } // end of foreach } $i = 0; $html = ''; $counter = 0; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-xs-4 col-md-4 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; if (!empty($item['tool']['custom_icon'])) { $original_image = Display::img($item['tool']['image'], null, array('id' => 'toolimage_' . $item['tool']['id'])); } else { $original_image = Display::return_icon($image, null, array('id' => 'toolimage_' . $item['tool']['id']), ICON_SIZE_BIG, false); } switch ($image) { case 'scormbuilder.png': if (api_is_allowed_to_edit(null, true)) { $item['url_params']['href'] .= '&isStudentView=true'; } $image = $original_image; $lp_id = self::get_published_lp_id_from_link($item['link']); if ($lp_id) { $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id()); $path = $lp->get_preview_image_path(64); if ($path) { $image = '<img src="' . $path . '">'; } } break; default: $image = $original_image; } $data .= Display::url($image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; if ($counter == 2) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'activity': if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-md-6 course-tool">'; $content = $item['extra']; $content .= $item['visibility']; $content .= $item['icon']; $content .= $item['link']; $html .= Display::div($content, array('class' => 'activity_content')); $html .= '</div>'; if ($counter == 1) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return array('content' => $html, 'tool_list' => $items); }
/** * @deprecated 25-JAN-2010: See api_mail() and api_mail_html(), mail.lib.inc.php * * Send an email. * * Wrapper function for the standard php mail() function. Change this function * to your needs. The parameters must follow the same rules as the standard php * mail() function. Please look at the documentation on http://php.net/manual/en/function.mail.php * @param string $to * @param string $subject * @param string $message * @param string $additional_headers * @param string $additionalParameters * @author Ivan Tcholakov, 04-OCT-2009, a reworked version of this function. * @link http://www.dokeos.com/forum/viewtopic.php?t=15557 */ function api_send_mail($to, $subject, $message, $additional_headers = null, $additionalParameters = array()) { require_once api_get_path(LIBRARY_PATH) . 'phpmailer/class.phpmailer.php'; if (empty($platform_email['SMTP_FROM_NAME'])) { $platform_email['SMTP_FROM_NAME'] = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); } if (empty($platform_email['SMTP_FROM_EMAIL'])) { $platform_email['SMTP_FROM_EMAIL'] = api_get_setting('emailAdministrator'); } $matches = array(); if (preg_match('/([^<]*)<(.+)>/si', $to, $matches)) { $recipient_name = trim($matches[1]); $recipient_email = trim($matches[2]); } else { $recipient_name = ''; $recipient_email = trim($to); } $sender_name = ''; $sender_email = ''; $extra_headers = $additional_headers; // Regular expression to test for valid email address. // This should actually be revised to use the complete RFC3696 description. // http://tools.ietf.org/html/rfc3696#section-3 //$regexp = "^[0-9a-z_\.+-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$"; // Deprecated, 13-OCT-2010. $mail = new PHPMailer(); $mail->CharSet = $platform_email['SMTP_CHARSET']; $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; if ($platform_email['SMTP_AUTH']) { $mail->SMTPAuth = 1; $mail->Username = $platform_email['SMTP_USER']; $mail->Password = $platform_email['SMTP_PASS']; } $mail->Priority = 3; // 5 = low, 1 = high $mail->AddCustomHeader('Errors-To: ' . $platform_email['SMTP_FROM_EMAIL']); $mail->IsHTML(0); $mail->SMTPKeepAlive = true; // Attachments. // $mail->AddAttachment($path); // $mail->AddAttachment($path, $filename); if ($sender_email != '') { $mail->From = $sender_email; $mail->Sender = $sender_email; } else { $mail->From = $platform_email['SMTP_FROM_EMAIL']; $mail->Sender = $platform_email['SMTP_FROM_EMAIL']; } if ($sender_name != '') { $mail->FromName = $sender_name; } else { $mail->FromName = $platform_email['SMTP_FROM_NAME']; } $mail->Subject = $subject; $mail->Body = $message; // Only valid address are to be accepted. if (api_valid_email($recipient_email)) { $mail->AddAddress($recipient_email, $recipient_name); } if ($extra_headers != '') { $mail->AddCustomHeader($extra_headers); } // Send mail. if (!$mail->Send()) { return 0; } $plugin = new AppPlugin(); $installedPluginsList = $plugin->getInstalledPluginListObject(); foreach ($installedPluginsList as $installedPlugin) { if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additionalParameters)) { $clockworksmsObject = new Clockworksms(); $clockworksmsObject->send($additionalParameters); } } // Clear all the addresses. $mail->ClearAddresses(); return 1; }