Example #1
0
                    exit;
                }
            } else {
                // Insert mode
                if (true) {
                    $file = $_FILES['user_upload'];
                    $file_comment = $data['file_comment'];
                    if (empty($group_id)) {
                        $insert_id = AnnouncementManager::add_announcement($data['title'], $data['content'], $data['users'], $file, $file_comment, null, $sendToUsersInSession);
                    } else {
                        $insert_id = AnnouncementManager::add_group_announcement($data['title'], $data['content'], array('GROUP:' . $group_id), $data['users'], $file, $file_comment, $sendToUsersInSession);
                    }
                    Display::addFlash(Display::return_message(get_lang('AnnouncementAdded'), 'success'));
                    /* MAIL FUNCTION */
                    if (isset($data['email_ann']) && $data['email_ann']) {
                        AnnouncementManager::send_email($insert_id, $sendToUsersInSession);
                    }
                    header('Location: ' . $homeUrl);
                    exit;
                }
                // end condition token
            }
        }
        $content = $form->returnForm();
        break;
}
if (!empty($_GET['remind_inactive'])) {
    $to[] = 'USER:'******'remind_inactive']);
}
if (!empty($group_id)) {
    $group_properties = GroupManager::get_group_properties($group_id);
Example #2
0
                     $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
                     $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
                 } else {
                     $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
                 }
             }
             $item['photo'] = Display::img($user_info['avatar_small'], $user_info['complete_name'], [], false);
             $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
         }
     }
     break;
 case 'get_course_announcements':
     $columns = array('title', 'username', 'insert_date', 'actions');
     $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
     $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
     $result = AnnouncementManager::getAnnouncements(null, null, false, $start, $limit, $sidx, $sord, $titleToSearch, $userIdToSearch);
     break;
 case 'get_work_teacher':
     $columns = array('type', 'title', 'sent_date', 'expires_on', 'amount', 'actions');
     $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition);
     break;
 case 'get_work_student':
     $columns = array('type', 'title', 'expires_on', 'feedback', 'last_upload', 'others');
     $result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition);
     break;
 case 'get_work_user_list_all':
     if (isset($_GET['type']) && $_GET['type'] == 'simple') {
         $columns = array('firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'correction', 'actions');
     } else {
         $columns = array('firstname', 'lastname', 'title', 'qualification', 'sent_date', 'correction', 'actions');
     }
 /**
  * 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;
 }
Example #4
0
 /**
  * @param int $item_id
  * @param array $sentTo
  * @return int
  */
 public function store_agenda_item_as_announcement($item_id, $sentTo = array())
 {
     $table_agenda = Database::get_course_table(TABLE_AGENDA);
     $course_id = api_get_course_int_id();
     // Check params
     if (empty($item_id) or $item_id != strval(intval($item_id))) {
         return -1;
     }
     // Get the agenda item.
     $item_id = intval($item_id);
     $sql = "SELECT * FROM {$table_agenda}\n                WHERE c_id = {$course_id} AND id = " . $item_id;
     $res = Database::query($sql);
     if (Database::num_rows($res) > 0) {
         $row = Database::fetch_array($res, 'ASSOC');
         // Sending announcement
         if (!empty($sentTo)) {
             $id = AnnouncementManager::add_announcement($row['title'], $row['content'], $sentTo, null, null, $row['end_date']);
             AnnouncementManager::send_email($id);
             return $id;
         }
     }
     return -1;
 }
Example #5
0
 /**
  * Shows the right menu of the Social Network tool
  *
  * @param string $show highlight link possible values:
  * group_add,
  * home,
  * messages,
  * messages_inbox,
  * messages_compose ,
  * messages_outbox,
  * invitations,
  * shared_profile,
  * friends,
  * groups search
  * @param int $group_id group id
  * @param int $user_id user id
  * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  * @param bool $show_delete_account_button
  *
  */
 public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false)
 {
     if (empty($user_id)) {
         $user_id = api_get_user_id();
     }
     $usergroup = new UserGroup();
     $user_info = api_get_user_info($user_id, true);
     $current_user_id = api_get_user_id();
     $current_user_info = api_get_user_info($current_user_id, true);
     if ($current_user_id == $user_id) {
         $user_friend_relation = null;
     } else {
         $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
     }
     $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups');
     // get count unread message and total invitations
     $count_unread_message = MessageManager::get_number_of_messages(true);
     $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
     $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
     $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
     $group_pending_invitations = count($group_pending_invitations);
     $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
     $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : '';
     $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL);
     $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL);
     $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL);
     $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), '', ICON_SIZE_SMALL);
     $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL);
     $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL);
     $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
     $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), '', ICON_SIZE_SMALL);
     $html = '';
     $active = null;
     if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) {
         $links = '<ul class="nav nav-pills nav-stacked">';
         $active = $show == 'home' ? 'active' : null;
         $links .= '
             <li class="home-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
                     ' . $homeIcon . ' ' . get_lang('Home') . '
                 </a>
             </li>';
         $active = $show == 'messages' ? 'active' : null;
         $links .= '
             <li class="messages-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
                     ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
                 </a>
             </li>';
         //Invitations
         $active = $show == 'invitations' ? 'active' : null;
         $links .= '
             <li class="invitations-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
                     ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
                 </a>
             </li>';
         //Shared profile and groups
         $active = $show == 'shared_profile' ? 'active' : null;
         $links .= '
             <li class="shared-profile-icon' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
                     ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
                 </a>
             </li>';
         $active = $show == 'friends' ? 'active' : null;
         $links .= '
             <li class="friends-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
                     ' . $friendsIcon . ' ' . get_lang('Friends') . '
                 </a>
             </li>';
         $active = $show == 'browse_groups' ? 'active' : null;
         $links .= '
             <li class="browse-groups-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
                     ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
                 </a>
             </li>';
         //Search users
         $active = $show == 'search' ? 'active' : null;
         $links .= '
             <li class="search-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
                     ' . $searchIcon . ' ' . get_lang('Search') . '
                 </a>
             </li>';
         //My files
         $active = $show == 'myfiles' ? 'active' : null;
         $myFiles = '
             <li class="myfiles-icon ' . $active . '">
                 <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
                     ' . $filesIcon . ' ' . get_lang('MyFiles') . '
                 </a>
             </li>';
         if (api_get_setting('platform.allow_my_files') === 'false') {
             $myFiles = '';
         }
         $links .= $myFiles;
         $links .= '</ul>';
         $html .= Display::panelCollapse(get_lang('SocialNetwork'), $links, 'social-network-menu', null, 'sn-sidebar', 'sn-sidebar-collapse');
     }
     if (in_array($show, $show_groups) && !empty($group_id)) {
         $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show);
     }
     if ($show == 'shared_profile') {
         $links = '<ul class="nav nav-pills nav-stacked">';
         // My own profile
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $links .= '
                 <li class="home-icon ' . $active . '">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
                         ' . $homeIcon . ' ' . get_lang('Home') . '
                     </a>
                 </li>
                 <li class="messages-icon ' . $active . '">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
                         ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
                     </a>
                 </li>';
             $active = $show == 'invitations' ? 'active' : null;
             $links .= '
                 <li class="invitations-icon' . $active . '">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
                         ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
                     </a>
                 </li>';
             $links .= '
                 <li class="shared-profile-icon active">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
                         ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
                     </a>
                 </li>
                 <li class="friends-icon">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
                         ' . $friendsIcon . ' ' . get_lang('Friends') . '
                     </a>
                 </li>
                 <li class="browse-groups-icon">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
                         ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
                     </a>
                 </li>';
             $active = $show == 'search' ? 'active' : null;
             $links .= '
                 <li class="search-icon ' . $active . '">
                     <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
                         ' . $searchIcon . ' ' . get_lang('Search') . '
                     </a>
                 </li>';
             $active = $show == 'myfiles' ? 'active' : null;
             $myFiles = '
                 <li class="myfiles-icon ' . $active . '">
                  <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
                         ' . $filesIcon . ' ' . get_lang('MyFiles') . '
                     </a>
                 </li>';
             if (api_get_setting('platform.allow_my_files') === 'false') {
                 $myFiles = '';
             }
             $links .= $myFiles;
         }
         // My friend profile.
         if ($user_id != api_get_user_id()) {
             $sendMessageText = get_lang('SendMessage');
             $sendMessageIcon = Display::return_icon('new-message.png', $sendMessageText);
             $sendMesssageUrl = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?' . http_build_query(['a' => 'get_user_popup', 'user_id' => $user_id]);
             $links .= '<li>';
             $links .= Display::url("{$sendMessageIcon} {$sendMessageText}", $sendMesssageUrl, ['class' => 'ajax', 'title' => $sendMessageText, 'data-title' => $sendMessageText]);
             $links .= '</li>';
         }
         // Check if I already sent an invitation message
         $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
         if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
             $links .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . '&nbsp;&nbsp;' . get_lang('YouAlreadySentAnInvitation') . '</a></li>';
         } else {
             if (!$show_full_profile) {
                 $links .= '<li><a class="btn-to-send-invitation" href="#" data-send-to="' . $user_id . '" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . '&nbsp;' . get_lang('SendInvitation') . '</a></li>';
             }
         }
         $links .= '</ul>';
         $html .= Display::panelCollapse(get_lang('SocialNetwork'), $links, 'social-network-menu', null, 'sn-sidebar', 'sn-sidebar-collapse');
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $personal_course_list = UserManager::get_personal_session_course_list($user_id);
             $course_list_code = array();
             $i = 1;
             if (is_array($personal_course_list)) {
                 foreach ($personal_course_list as $my_course) {
                     if ($i <= 10) {
                         $course_list_code[] = array('code' => $my_course['code']);
                     } else {
                         break;
                     }
                     $i++;
                 }
                 // To avoid repeated courses
                 $course_list_code = ArrayClass::array_unique_dimensional($course_list_code);
             }
             // Announcements
             $my_announcement_by_user_id = intval($user_id);
             $announcements = array();
             foreach ($course_list_code as $course) {
                 $course_info = api_get_course_info($course['code']);
                 if (!empty($course_info)) {
                     $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id);
                     if (!empty($content)) {
                         $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']);
                         $announcements[] = Display::tag('li', $url);
                     }
                 }
             }
             if (!empty($announcements)) {
                 $html .= '<div class="social_menu_items">';
                 $html .= '<ul>';
                 foreach ($announcements as $announcement) {
                     $html .= $announcement;
                 }
                 $html .= '</ul>';
                 $html .= '</div>';
             }
         }
     }
     if ($show_delete_account_button) {
         $html .= '<div class="sidebar-nav"><ul><li>';
         $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php';
         $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url);
         $html .= '</li></ul></div>';
     }
     $html .= '';
     return $html;
 }
 /**
  * Email message
  * @param int $receiverUserId
  *
  * @return string
  */
 public function message($receiverUserId)
 {
     $content = $this->announcement('content');
     $session_id = $this->session_id;
     $content = AnnouncementManager::parse_content($receiverUserId, $content, $this->course('code'), $session_id);
     $user_email = $this->sender('mail');
     //$course_param = api_get_cidreq();
     // Build the link by hand because api_get_cidreq() doesn't accept course params
     $course_param = 'cidReq=' . api_get_course_id() . '&amp;id_session=' . $session_id . '&amp;gidReq=' . api_get_group_id();
     $course_name = $this->course('title');
     $result = "<div>{$content}</div>";
     // Adding attachment
     $attachment = $this->attachment();
     if (!empty($attachment)) {
         $result .= '<br />';
         $result .= Display::url($attachment['filename'], api_get_path(WEB_CODE_PATH) . 'announcements/download.php?file=' . basename($attachment['path']) . '&' . $course_param) . '<br />';
     }
     $result .= '<hr />';
     $sender_name = api_get_person_name($this->sender('firstName'), $this->sender('lastName'), PERSON_NAME_EMAIL_ADDRESS);
     $result .= '<a href="mailto:' . $user_email . '">' . $sender_name . '</a><br/>';
     $result .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?' . $course_param . '">' . $course_name . '</a><br/>';
     return $result;
 }
                            $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
                        }
                        if ($iterator < $bottomAnnouncement) {
                            $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&down=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('down.gif', get_lang('Down')) . "</a>";
                        } else {
                            $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
                        }
                        if (api_is_allowed_to_edit(false, true)) {
                            $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=delete&id=" . $myrow['id'] . "&sec_token=" . $stok . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . "</a>";
                        }
                        $iterator++;
                        echo Display::tag('td align="center"', $modify_icons, array('class' => 'announcements-list-line-actions'));
                    }
                    echo "</tr>";
                }
                $displayed[] = $myrow['id'];
            }
            // end while
            echo "</table>";
        }
    }
}
// end: if ($displayAnnoucementList)
if (isset($_GET['action']) && $_GET['action'] == 'view') {
    AnnouncementManager::display_announcement($announcement_id);
}
/*		FOOTER		*/
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
    //we are not in learnpath tool
    Display::display_footer();
}
Example #8
0
 /**
  * Shows the right menu of the Social Network tool
  *
  * @param string highlight link possible values: group_add, home, messages, messages_inbox, messages_compose ,messages_outbox ,invitations, shared_profile, friends, groups search
  * @param int group id
  * @param int user id
  * @param bool show profile or not (show or hide the user image/information)
  *
  */
 public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false)
 {
     if (empty($user_id)) {
         $user_id = api_get_user_id();
     }
     $usergroup = new UserGroup();
     $user_info = api_get_user_info($user_id, true);
     $current_user_id = api_get_user_id();
     $current_user_info = api_get_user_info($current_user_id, true);
     if ($current_user_id == $user_id) {
         $user_friend_relation = null;
     } else {
         $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
     }
     $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups');
     // get count unread message and total invitations
     $count_unread_message = MessageManager::get_number_of_messages(true);
     $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : '';
     $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
     $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
     $group_pending_invitations = count($group_pending_invitations);
     $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
     $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : '';
     $html = '<div class="social-menu">';
     if (in_array($show, $show_groups) && !empty($group_id)) {
         //--- Group image
         $group_info = $usergroup->get($group_id);
         $big = $usergroup->get_picture_group($group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG);
         $html .= '<div class="social-content-image">';
         $html .= '<div class="well social-background-content">';
         $html .= Display::url('<img src=' . $big['file'] . ' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH) . 'main/social/groups.php?id=' . $group_id);
         if ($usergroup->is_group_admin($group_id, api_get_user_id())) {
             $html .= '<div id="edit_image" class="hidden_message" style="display:none"><a href="' . api_get_path(WEB_PATH) . 'main/social/group_edit.php?id=' . $group_id . '">' . get_lang('EditGroup') . '</a></div>';
         }
         $html .= '</div>';
         $html .= '</div>';
     } else {
         $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true);
         $big_image = UserManager::get_picture_user($user_id, $img_array['file'], '', USER_IMAGE_SIZE_BIG);
         $big_image = $big_image['file'];
         $normal_image = $img_array['dir'] . $img_array['file'];
         //--- User image
         $html .= '<div class="well social-background-content">';
         if ($img_array['file'] != 'unknown.jpg') {
             $html .= '<a class="thumbnail ajax" href="' . $big_image . '"><img src=' . $normal_image . ' /> </a>';
         } else {
             $html .= '<img src=' . $normal_image . ' width="110px" />';
         }
         if (api_get_user_id() == $user_id) {
             $html .= '<div id="edit_image" class="hidden_message" style="display:none">';
             $html .= '<a href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php">' . get_lang('EditProfile') . '</a></div>';
         }
         $html .= '</div>';
     }
     if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) {
         $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">';
         $active = $show == 'home' ? 'active' : null;
         $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>';
         if (api_get_setting('allow_message_tool') == 'true') {
             $active = $show == 'messages' ? 'active' : null;
             $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>';
         }
         // Invitations
         if (api_get_setting('allow_message_tool') == 'true') {
             $active = $show == 'invitations' ? 'active' : null;
             $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>';
         }
         //Shared profile and groups
         $active = $show == 'shared_profile' ? 'active' : null;
         $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array()) . get_lang('ViewMySharedProfile') . '</a></li>';
         $active = $show == 'friends' ? 'active' : null;
         $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li>';
         $active = $show == 'browse_groups' ? 'active' : null;
         $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>';
         //Search users
         $active = $show == 'search' ? 'active' : null;
         $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>';
         $html .= '</ul>
               </div>';
     }
     if (in_array($show, $show_groups) && !empty($group_id)) {
         $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show);
     }
     if ($show == 'shared_profile') {
         //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('Menu').'</span></div>';
         $html .= '<div class="well sidebar-nav">
                 <ul class="nav nav-list">';
         // My own profile
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>';
             if (api_get_setting('allow_message_tool') == 'true') {
                 $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>';
                 $active = $show == 'invitations' ? 'active' : null;
                 $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>';
             }
             $html .= '<li class="active"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array('style' => 'float:left')) . '' . get_lang('ViewMySharedProfile') . '</a></li>
                       <li><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li>
                       <li><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>';
             $active = $show == 'search' ? 'active' : null;
             $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>';
         }
         // My friend profile
         if (api_get_setting('allow_message_tool') == 'true') {
             if ($user_id != api_get_user_id()) {
                 $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_message_to_user(\'' . $user_id . '\');" title="' . get_lang('SendMessage') . '">';
                 $html .= Display::return_icon('compose_message.png', get_lang('SendMessage')) . '&nbsp;&nbsp;' . get_lang('SendMessage') . '</a></li>';
             }
             //check if I already sent an invitation message
             $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
             if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
                 $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . '&nbsp;&nbsp;' . get_lang('YouAlreadySentAnInvitation') . '</a></li>';
             } else {
                 if (!$show_full_profile) {
                     $html .= '<li><a  href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\'' . $user_id . '\');" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . '&nbsp;' . get_lang('SendInvitation') . '</a></li>';
                 }
             }
         }
         //@todo check if user is online and if it's a friend to show the chat link
         if (api_is_global_chat_enabled()) {
             $user_name = $user_info['complete_name'];
             if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) {
                 if ($user_id != api_get_user_id()) {
                     //Only show chat if I'm available to talk
                     if ($current_user_info['user_is_online_in_chat'] == 1) {
                         $options = array('onclick' => "javascript:chatWith('" . $user_id . "', '" . Security::remove_XSS($user_name) . "', '" . $user_info['user_is_online_in_chat'] . "')");
                         $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
                         $html .= Display::tag('li', Display::url($chat_icon . '&nbsp;&nbsp;' . get_lang('Chat'), 'javascript:void(0);', $options));
                     }
                 }
             } else {
                 // Do something?
                 if ($user_id != api_get_user_id()) {
                     if ($current_user_info['user_is_online_in_chat'] == 1) {
                         $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name));
                         $options = array('onclick' => "javascript:chatNotYetWith('" . $message . "')");
                         $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
                         $html .= Display::tag('li', Display::url($chat_icon . '&nbsp;&nbsp;' . get_lang('Chat'), 'javascript:void(0);', $options));
                     }
                 }
             }
         }
         $html .= '</ul></div>';
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $personal_course_list = UserManager::get_personal_session_course_list($user_id);
             $course_list_code = array();
             $i = 1;
             if (is_array($personal_course_list)) {
                 foreach ($personal_course_list as $my_course) {
                     if ($i <= 10) {
                         $course_list_code[] = array('code' => $my_course['code']);
                     } else {
                         break;
                     }
                     $i++;
                 }
                 //to avoid repeted courses
                 $course_list_code = ArrayClass::array_unique_dimensional($course_list_code);
             }
             //-----Announcements
             $my_announcement_by_user_id = intval($user_id);
             $announcements = array();
             foreach ($course_list_code as $course) {
                 $course_info = api_get_course_info($course['code']);
                 if (!empty($course_info)) {
                     $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id);
                     if (!empty($content)) {
                         $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']);
                         $announcements[] = Display::tag('li', $url);
                     }
                 }
             }
             if (!empty($announcements)) {
                 //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('ToolAnnouncement').'</span></div>';
                 $html .= '<div class="social_menu_items">';
                 $html .= '<ul>';
                 foreach ($announcements as $announcement) {
                     $html .= $announcement;
                 }
                 $html .= '</ul>';
                 $html .= '</div>';
             }
         }
     }
     if ($show_delete_account_button) {
         $html .= '<div class="sidebar-nav"><ul><li>';
         $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php';
         $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url);
         $html .= '</li></ul></div>';
     }
     $html .= '</div>';
     return $html;
 }
 /**
  * @param $stok
  * @param $announcement_number
  */
 public static function getAnnouncements($stok, $announcement_number)
 {
     $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
     $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $user_id = api_get_user_id();
     $group_id = api_get_group_id();
     $session_id = api_get_session_id();
     $condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id');
     $course_id = api_get_course_int_id();
     $_course = api_get_course_info();
     $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id());
     $allowUserEditSetting = api_get_course_setting('allow_user_edit_announcement');
     if (api_is_allowed_to_edit(false, true) || $allowUserEditSetting && !api_is_anonymous()) {
         // A.1. you are a course admin with a USER filter
         // => see only the messages of this specific user + the messages of the group (s)he is member of.
         //if (!empty($user_id)) {
         if (0) {
             if (is_array($group_memberships) && count($group_memberships) > 0) {
                 $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                announcement.id = ip.ref AND\n                                ip.tool = 'announcement' AND\n                                (\n                                    ip.to_user_id = {$user_id} OR\n                                    ip.to_group_id IS NULL OR\n                                    ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")\n                                ) AND\n                                ip.visibility IN ('1', '0')\n                                {$condition_session}\n                            ORDER BY display_order DESC";
             } else {
                 $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                announcement.id = ip.ref AND\n                                ip.tool ='announcement' AND\n                                (ip.to_user_id = {$user_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND\n                                ip.visibility IN ('1', '0')\n                            {$condition_session}\n                            ORDER BY display_order DESC";
             }
         } elseif ($group_id != 0) {
             // A.2. you are a course admin with a GROUP filter
             // => see only the messages of this specific group
             $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n                        FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            AND ip.visibility<>'2'\n                            AND (ip.to_group_id = {$group_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL)\n                            {$condition_session}\n                        GROUP BY ip.ref\n                        ORDER BY display_order DESC";
         } else {
             // A.3 you are a course admin without any group or user filter
             // A.3.a you are a course admin without user or group filter but WITH studentview
             // => see all the messages of all the users and groups without editing possibilities
             if (isset($isStudentView) and $isStudentView == "true") {
                 $sql = "SELECT\n                        announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n                        FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            AND ip.visibility='1'\n                            {$condition_session}\n                        GROUP BY ip.ref\n                        ORDER BY display_order DESC";
             } else {
                 // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
                 // => see all the messages of all the users and groups with editing possibilities
                 $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                announcement.id = ip.ref\n                                AND ip.tool='announcement'\n                                AND (ip.visibility='0' or ip.visibility='1')\n                                {$condition_session}\n                            GROUP BY ip.ref\n                            ORDER BY display_order DESC";
             }
         }
     } else {
         // STUDENT
         if (is_array($group_memberships) && count($group_memberships) > 0) {
             if ($allowUserEditSetting && !api_is_anonymous()) {
                 if (api_get_group_id() == 0) {
                     // No group
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR (\n                                ip.to_user_id='" . $user_id . "' OR\n                                (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n                            )\n                        ) ";
                 } else {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . ")\n                        )";
                 }
             } else {
                 if (api_get_group_id() == 0) {
                     $cond_user_id = " AND (\n                            ip.to_user_id={$user_id} OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n                        ) ";
                 } else {
                     $cond_user_id = " AND (\n                            ip.to_user_id={$user_id} OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . api_get_group_id() . "))\n                        )";
                 }
             }
             $sql = "SELECT\n                            announcement.*,\n                            ip.visibility,\n                            ip.to_group_id,\n                            ip.insert_user_id,\n                            ip.insert_date\n                        FROM {$tbl_announcement} announcement,\n                        {$tbl_item_property} ip\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            {$cond_user_id}\n                            {$condition_session} AND\n                            ip.visibility='1'\n                        ORDER BY display_order DESC";
         } else {
             if ($user_id) {
                 if ($allowUserEditSetting && !api_is_anonymous()) {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . api_get_user_id() . "' OR\n                            (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL))\n                        ) ";
                 } else {
                     $cond_user_id = " AND (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) ";
                 }
                 $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n    \t\t\t\t\t\tannouncement.c_id = {$course_id} AND\n\t\t\t\t\t\t\tip.c_id = {$course_id} AND\n    \t\t\t\t\t\tannouncement.id = ip.ref AND\n    \t\t\t\t\t\tip.tool='announcement'\n    \t\t\t\t\t\t{$cond_user_id}\n    \t\t\t\t\t\t{$condition_session}\n    \t\t\t\t\t\tAND ip.visibility='1'\n    \t\t\t\t\t\tAND announcement.session_id IN(0, " . api_get_session_id() . ")\n\t\t\t\t\t\tORDER BY display_order DESC";
             } else {
                 if ($allowUserEditSetting && !api_is_anonymous()) {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id='0' OR ip.to_group_id IS NULL\n                        )";
                 } else {
                     $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL ";
                 }
                 $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref AND\n                            ip.tool='announcement'\n                            {$cond_user_id}\n                            {$condition_session} AND\n                            ip.visibility='1' AND\n                            announcement.session_id IN ( 0," . api_get_session_id() . ")";
             }
         }
     }
     $result = Database::query($sql);
     $num_rows = Database::num_rows($result);
     $html = null;
     if ($num_rows == 0) {
         if ((api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) and (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')) {
             $html .= '<div id="no-data-view">';
             $html .= '<h3>' . get_lang('Announcements') . '</h3>';
             $html .= Display::return_icon('valves.png', '', array(), 64);
             $html .= '<div class="controls">';
             $html .= Display::url(get_lang('AddAnnouncement'), api_get_self() . "?" . api_get_cidreq() . "&action=add", array('class' => 'btn btn-primary'));
             $html .= '</div>';
             $html .= '</div>';
         } else {
             $html = Display::return_message(get_lang('NoAnnouncements'), 'warning');
         }
         return $html;
     }
     $iterator = 1;
     $bottomAnnouncement = $announcement_number;
     $origin = null;
     $html .= '<table width="100%" class="data_table announcements-list">';
     $ths = Display::tag('th', get_lang('Title'));
     $ths .= Display::tag('th', get_lang('By'));
     $ths .= Display::tag('th', get_lang('LastUpdateDate'));
     if (api_is_allowed_to_edit(false, true) or api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) {
         $ths .= Display::tag('th', get_lang('Modify'));
     }
     $html .= Display::tag('tr', $ths);
     $displayed = array();
     while ($myrow = Database::fetch_array($result, 'ASSOC')) {
         if (!in_array($myrow['id'], $displayed)) {
             $sent_to_icon = '';
             // the email icon
             if ($myrow['email_sent'] == '1') {
                 $sent_to_icon = ' ' . Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'));
             }
             $title = $myrow['title'] . $sent_to_icon;
             $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id);
             $myrow['visibility'] = $item_visibility;
             // the styles
             if ($myrow['visibility'] == '0') {
                 $style = 'invisible';
             } else {
                 $style = '';
             }
             $html .= '<tr class="announcements-list-line">';
             // show attachment list
             $attachment_list = AnnouncementManager::get_attachment($myrow['id']);
             $attachment_icon = '';
             if (count($attachment_list) > 0) {
                 $attachment_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment'));
             }
             /* TITLE */
             $user_info = api_get_user_info($myrow['insert_user_id']);
             $username = sprintf(get_lang("LoginX"), $user_info['username']);
             $username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title' => $username));
             $title = Display::url($title . $attachment_icon, api_get_self() . '?' . api_get_cidreq() . '&action=view&id=' . $myrow['id']);
             $html .= Display::tag('td', Security::remove_XSS($title), array('class' => 'announcements-list-line-title ' . $style));
             $html .= Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user'));
             $html .= Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), array('class' => 'announcements-list-line-datetime'));
             // we can edit if : we are the teacher OR the element belongs to
             // the session we are coaching OR the option to allow users to edit is on
             if (api_is_allowed_to_edit(false, true) or api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) {
                 $modify_icons = "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=modify&id=" . $myrow['id'] . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>";
                 if ($myrow['visibility'] == 1) {
                     $image_visibility = "visible";
                     $alt_visibility = get_lang('Hide');
                 } else {
                     $image_visibility = "invisible";
                     $alt_visibility = get_lang('Visible');
                 }
                 $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&origin=" . $origin . "&action=showhide&id=" . $myrow['id'] . "&sec_token=" . $stok . "\">" . Display::return_icon($image_visibility . '.png', $alt_visibility, '', ICON_SIZE_SMALL) . "</a>";
                 // DISPLAY MOVE UP COMMAND only if it is not the top announcement
                 if ($iterator != 1) {
                     $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=move&up=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('up.gif', get_lang('Up')) . "</a>";
                 } else {
                     $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
                 }
                 if ($iterator < $bottomAnnouncement) {
                     $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=move&down=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('down.gif', get_lang('Down')) . "</a>";
                 } else {
                     $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
                 }
                 if (api_is_allowed_to_edit(false, true)) {
                     $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=delete&id=" . $myrow['id'] . "&sec_token=" . $stok . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, api_get_system_encoding())) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . "</a>";
                 }
                 $iterator++;
                 $html .= Display::tag('td', $modify_icons, array('class' => 'announcements-list-line-actions'));
             }
             $html .= "</tr>";
         }
         $displayed[] = $myrow['id'];
     }
     $html .= "</table>";
     return $html;
 }
 /**
  * @param $stok
  * @param $announcement_number
  * @param bool $getCount
  * @param null $start
  * @param null $limit
  * @param string $sidx
  * @param string $sord
  * @param string $titleToSearch
  * @param int $userIdToSearch
  *
  * @return array
  */
 public static function getAnnouncements($stok, $announcement_number, $getCount = false, $start = null, $limit = null, $sidx = '', $sord = '', $titleToSearch = '', $userIdToSearch = 0)
 {
     $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
     $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $user_id = api_get_user_id();
     $group_id = api_get_group_id();
     $session_id = api_get_session_id();
     $condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id');
     $course_id = api_get_course_int_id();
     $_course = api_get_course_info();
     $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id());
     $allowUserEditSetting = api_get_course_setting('announcement.allow_user_edit_announcement');
     $select = ' DISTINCT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date';
     if ($getCount) {
         $select = ' COUNT(announcement.iid) count';
     }
     $searchCondition = '';
     if (!empty($titleToSearch)) {
         $titleToSearch = Database::escape_string($titleToSearch);
         $searchCondition .= " AND (title LIKE '%{$titleToSearch}%')";
     }
     if (!empty($userIdToSearch)) {
         $userIdToSearch = intval($userIdToSearch);
         $searchCondition .= " AND (ip.insert_user_id = {$userIdToSearch})";
     }
     if (api_is_allowed_to_edit(false, true) || $allowUserEditSetting && !api_is_anonymous()) {
         // A.1. you are a course admin with a USER filter
         // => see only the messages of this specific user + the messages of the group (s)he is member of.
         //if (!empty($user_id)) {
         if (0) {
             if (is_array($group_memberships) && count($group_memberships) > 0) {
                 $sql = "SELECT {$select}\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                announcement.id = ip.ref AND\n                                ip.tool = 'announcement' AND\n                                (\n                                    ip.to_user_id = {$user_id} OR\n                                    ip.to_group_id IS NULL OR\n                                    ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")\n                                ) AND\n                                ip.visibility IN ('1', '0')\n                                {$condition_session}\n                                {$searchCondition}\n                            ORDER BY display_order DESC";
             } else {
                 $sql = "SELECT {$select}\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                announcement.id = ip.ref AND\n                                ip.tool ='announcement' AND\n                                (ip.to_user_id = {$user_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND\n                                ip.visibility IN ('1', '0')\n                            {$condition_session}\n                            {$searchCondition}\n                            ORDER BY display_order DESC";
             }
         } elseif ($group_id != 0) {
             // A.2. you are a course admin with a GROUP filter
             // => see only the messages of this specific group
             $sql = "SELECT {$select}\n                        FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n                        ON (announcement.id = ip.ref AND ip.tool='announcement')\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            ip.visibility<>'2' AND\n                            (ip.to_group_id = {$group_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL)\n                            {$condition_session}\n                            {$searchCondition}\n                        ORDER BY display_order DESC";
             //GROUP BY ip.ref
         } else {
             // A.3 you are a course admin without any group or user filter
             // A.3.a you are a course admin without user or group filter but WITH studentview
             // => see all the messages of all the users and groups without editing possibilities
             if (isset($isStudentView) && $isStudentView == "true") {
                 $sql = "SELECT {$select}\n                        FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n                        ON (announcement.id = ip.ref AND ip.tool='announcement')\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            ip.tool='announcement' AND\n                            ip.visibility='1'\n                            {$condition_session}\n                            {$searchCondition}\n                        ORDER BY display_order DESC";
                 //GROUP BY ip.ref
             } else {
                 // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
                 // => see all the messages of all the users and groups with editing possibilities
                 $sql = "SELECT {$select}\n                            FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n                            ON (announcement.id = ip.ref AND ip.tool='announcement')\n                            WHERE\n                                announcement.c_id = {$course_id} AND\n                                ip.c_id = {$course_id} AND\n                                (ip.visibility='0' or ip.visibility='1')\n                                {$condition_session}\n                                {$searchCondition}\n                            ORDER BY display_order DESC";
                 //GROUP BY ip.ref
             }
         }
     } else {
         // STUDENT
         if (is_array($group_memberships) && count($group_memberships) > 0) {
             if ($allowUserEditSetting && !api_is_anonymous()) {
                 if ($group_id == 0) {
                     // No group
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR (\n                                ip.to_user_id='" . $user_id . "' OR\n                                (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n                            )\n                        ) ";
                 } else {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . ")\n                        )";
                 }
             } else {
                 if ($group_id == 0) {
                     $cond_user_id = " AND (\n                            ip.to_user_id = {$user_id} AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n                        ) ";
                 } else {
                     $cond_user_id = " AND (\n                            ip.to_user_id = {$user_id} AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . "))\n                        )";
                 }
             }
             $sql = "SELECT {$select}\n                        FROM {$tbl_announcement} announcement,\n                        {$tbl_item_property} ip\n                        WHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            {$cond_user_id}\n                            {$condition_session}\n                            {$searchCondition}\n                            AND ip.visibility='1'\n                        ORDER BY display_order DESC";
         } else {
             if ($user_id) {
                 if ($allowUserEditSetting && !api_is_anonymous()) {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . api_get_user_id() . "' OR\n                            (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL))\n                        ) ";
                 } else {
                     $cond_user_id = " AND (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) ";
                 }
                 $sql = "SELECT {$select}\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n    \t\t\t\t\t\tannouncement.c_id = {$course_id} AND\n\t\t\t\t\t\t\tip.c_id = {$course_id} AND\n    \t\t\t\t\t\tannouncement.id = ip.ref AND\n    \t\t\t\t\t\tip.tool='announcement'\n    \t\t\t\t\t\t{$cond_user_id}\n    \t\t\t\t\t\t{$condition_session}\n    \t\t\t\t\t\t{$searchCondition}\n    \t\t\t\t\t\tAND ip.visibility='1'\n    \t\t\t\t\t\tAND announcement.session_id IN(0, " . $session_id . ")\n\t\t\t\t\t\tORDER BY display_order DESC";
             } else {
                 if ($allowUserEditSetting && !api_is_anonymous()) {
                     $cond_user_id = " AND (\n                            ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id='0' OR ip.to_group_id IS NULL\n                        )";
                 } else {
                     $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL ";
                 }
                 $sql = "SELECT {$select}\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n                            announcement.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            announcement.id = ip.ref AND\n                            ip.tool='announcement'\n                            {$cond_user_id}\n                            {$condition_session}\n                            {$searchCondition}\n                            AND\n                            ip.visibility='1' AND\n                            announcement.session_id IN ( 0," . api_get_session_id() . ")";
             }
         }
     }
     if (!is_null($start) && !is_null($limit)) {
         $start = intval($start);
         $limit = intval($limit);
         $sql .= " LIMIT {$start}, {$limit}";
     }
     $result = Database::query($sql);
     if ($getCount) {
         $result = Database::fetch_array($result, 'ASSOC');
         return $result['count'];
     }
     $iterator = 1;
     $bottomAnnouncement = $announcement_number;
     $origin = null;
     $displayed = [];
     $results = [];
     $actionUrl = api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?' . api_get_cidreq();
     while ($myrow = Database::fetch_array($result, 'ASSOC')) {
         if (!in_array($myrow['id'], $displayed)) {
             $sent_to_icon = '';
             // the email icon
             if ($myrow['email_sent'] == '1') {
                 $sent_to_icon = ' ' . Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'));
             }
             $title = $myrow['title'] . $sent_to_icon;
             $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id);
             $myrow['visibility'] = $item_visibility;
             // show attachment list
             $attachment_list = AnnouncementManager::get_attachment($myrow['id']);
             $attachment_icon = '';
             if (count($attachment_list) > 0) {
                 $attachment_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment'));
             }
             /* TITLE */
             $user_info = api_get_user_info($myrow['insert_user_id']);
             $username = sprintf(get_lang("LoginX"), $user_info['username']);
             $username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title' => $username));
             $title = Display::url($title . $attachment_icon, $actionUrl . '&action=view&id=' . $myrow['id']);
             //$html .= Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user'));
             //$html .= Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), array('class' => 'announcements-list-line-datetime'));
             $modify_icons = '';
             // we can edit if : we are the teacher OR the element belongs to
             // the session we are coaching OR the option to allow users to edit is on
             if (api_is_allowed_to_edit(false, true) || api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) || api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) {
                 $modify_icons = "<a href=\"" . $actionUrl . "&action=modify&id=" . $myrow['id'] . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>";
                 if ($myrow['visibility'] == 1) {
                     $image_visibility = "visible";
                     $alt_visibility = get_lang('Hide');
                 } else {
                     $image_visibility = "invisible";
                     $alt_visibility = get_lang('Visible');
                 }
                 $modify_icons .= "<a href=\"" . $actionUrl . "&origin=" . $origin . "&action=showhide&id=" . $myrow['id'] . "&sec_token=" . $stok . "\">" . Display::return_icon($image_visibility . '.png', $alt_visibility, '', ICON_SIZE_SMALL) . "</a>";
                 // DISPLAY MOVE UP COMMAND only if it is not the top announcement
                 if ($iterator != 1) {
                     $modify_icons .= "<a href=\"" . $actionUrl . "&action=move&up=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('up.gif', get_lang('Up')) . "</a>";
                 } else {
                     $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
                 }
                 if ($iterator < $bottomAnnouncement) {
                     $modify_icons .= "<a href=\"" . $actionUrl . "&action=move&down=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('down.gif', get_lang('Down')) . "</a>";
                 } else {
                     $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
                 }
                 if (api_is_allowed_to_edit(false, true)) {
                     $modify_icons .= "<a href=\"" . $actionUrl . "&action=delete&id=" . $myrow['id'] . "&sec_token=" . $stok . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, api_get_system_encoding())) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . "</a>";
                 }
                 $iterator++;
             } else {
                 $modify_icons = Display::url(Display::return_icon('default.png'), $actionUrl . '&action=view&id=' . $myrow['id']);
             }
             $announcement = ['id' => $myrow["id"], 'title' => $title, 'username' => $username_span, 'insert_date' => api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), 'actions' => $modify_icons];
             $results[] = $announcement;
         }
         $displayed[] = $myrow['id'];
     }
     return $results;
 }
 /**
  * Email message
  *
  * @return string
  */
 public function message()
 {
     $title = $this->announcement('title');
     $title = stripslashes($title);
     $content = $this->announcement('content');
     $content = stripslashes($content);
     $content = AnnouncementManager::parse_content($content, $this->course('code'));
     $user_email = $this->sender('mail');
     $course_param = api_get_cidreq();
     $course_name = $this->course('title');
     $result = "<div>{$content}</div>";
     //Adding attachment
     $attachment = $this->attachement();
     if (!empty($attachment)) {
         $result .= '<br />';
         $result .= Display::url($attachment['filename'], api_get_path(WEB_CODE_PATH) . 'announcements/download.php?file=' . basename($attachment['path']) . '&' . $course_param) . '<br />';
     }
     $result .= '<hr />';
     $sender_name = api_get_person_name($this->sender('firstName'), $this->sender('lastName'), PERSON_NAME_EMAIL_ADDRESS);
     $result .= '<a href="mailto:' . $user_email . '">' . $sender_name . '</a><br/>';
     $result .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?' . $course_param . '">' . $course_name . '</a><br/>';
     return $result;
 }
Example #12
0
 /**
  * Shows the right menu of the Social Network tool
  *
  * @param string $show highlight link possible values:
  * group_add,
  * home,
  * messages,
  * messages_inbox,
  * messages_compose ,
  * messages_outbox,
  * invitations,
  * shared_profile,
  * friends,
  * groups search
  * @param int $group_id group id
  * @param int $user_id user id
  * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  * @param bool $show_delete_account_button
  *
  */
 public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false)
 {
     if (empty($user_id)) {
         $user_id = api_get_user_id();
     }
     $usergroup = new UserGroup();
     $user_info = api_get_user_info($user_id, true);
     $current_user_id = api_get_user_id();
     $current_user_info = api_get_user_info($current_user_id, true);
     if ($current_user_id == $user_id) {
         $user_friend_relation = null;
     } else {
         $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
     }
     $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups');
     // get count unread message and total invitations
     $count_unread_message = MessageManager::get_number_of_messages(true);
     $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
     $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
     $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
     $group_pending_invitations = count($group_pending_invitations);
     $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
     $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : '';
     $html = '';
     $active = null;
     if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) {
         $html .= '<div class="panel panel-default sidebar-nav">';
         $html .= '<div class="panel-body">';
         $html .= '<ul class="nav nav-pills nav-stacked">';
         $active = $show == 'home' ? 'active' : null;
         $html .= '<li class="home-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">' . Display::return_icon('social-home.png', get_lang('Home'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Home') . '</a></li>';
         $active = $show == 'messages' ? 'active' : null;
         $html .= '<li class="messages-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">' . Display::return_icon('social-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Messages') . $count_unread_message . '</a></li>';
         //Invitations
         $active = $show == 'invitations' ? 'active' : null;
         $html .= '<li class="invitations-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">' . Display::return_icon('social-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Invitations') . $total_invitations . '</a></li>';
         //Shared profile and groups
         $active = $show == 'shared_profile' ? 'active' : null;
         $html .= '<li class="shared-profile-icon' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">' . Display::return_icon('social-profile.png', get_lang('ViewMySharedProfile'), '', ICON_SIZE_SMALL) . ' ' . get_lang('ViewMySharedProfile') . '</a></li>';
         $active = $show == 'friends' ? 'active' : null;
         $html .= '<li class="friends-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">' . Display::return_icon('social-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Friends') . '</a></li>';
         $active = $show == 'browse_groups' ? 'active' : null;
         $html .= '<li class="browse-groups-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">' . Display::return_icon('social-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL) . ' ' . get_lang('SocialGroups') . '</a></li>';
         //Search users
         $active = $show == 'search' ? 'active' : null;
         $html .= '<li class="search-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">' . Display::return_icon('social-search.png', get_lang('Search'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Search') . '</a></li>';
         //My files
         $active = $show == 'myfiles' ? 'active' : null;
         $html .= '<li class="myfiles-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">' . Display::return_icon('social-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL) . ' ' . get_lang('MyFiles') . '</span></a></li>';
         $html .= '</ul></div></div>';
     }
     if (in_array($show, $show_groups) && !empty($group_id)) {
         $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show);
     }
     if ($show == 'shared_profile') {
         $html .= '<div class="panel panel-default sidebar-nav">';
         $html .= '<div class="panel-body">';
         $html .= '<ul class="nav nav-pills nav-stacked">';
         // My own profile
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $html .= '<li class="home-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">' . Display::return_icon('social-home.png', get_lang('Home'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Home') . '</a></li>
                       <li class="messages-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">' . Display::return_icon('social-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Messages') . $count_unread_message . '</a></li>';
             $active = $show == 'invitations' ? 'active' : null;
             $html .= '<li class="invitations-icon' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">' . Display::return_icon('social-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Invitations') . $total_invitations . '</a></li>';
             $html .= '<li class="shared-profile-icon active"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">' . Display::return_icon('social-profile.png', get_lang('ViewMySharedProfile'), '', ICON_SIZE_SMALL) . ' ' . get_lang('ViewMySharedProfile') . '</a></li>
                       <li class="friends-icon"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">' . Display::return_icon('social-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Friends') . '</a></li>
                       <li class="browse-groups-icon"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">' . Display::return_icon('social-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL) . ' ' . get_lang('SocialGroups') . '</a></li>';
             $active = $show == 'search' ? 'active' : null;
             $html .= '<li class="search-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">' . Display::return_icon('social-search.png', get_lang('Search'), '', ICON_SIZE_SMALL) . ' ' . get_lang('Search') . '</a></li>';
             $active = $show == 'myfiles' ? 'active' : null;
             $html .= '<li class="myfiles-icon ' . $active . '"><a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">' . Display::return_icon('social-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL) . ' ' . get_lang('MyFiles') . '</a></li>';
         }
         // My friend profile.
         if ($user_id != api_get_user_id()) {
             $html .= '<li><a href="#" class="btn-to-send-message" data-send-to="' . $user_id . '" title="' . get_lang('SendMessage') . '">';
             $html .= Display::return_icon('compose_message.png', get_lang('SendMessage')) . '&nbsp;&nbsp;' . get_lang('SendMessage') . '</a></li>';
         }
         // Check if I already sent an invitation message
         $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
         if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
             $html .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . '&nbsp;&nbsp;' . get_lang('YouAlreadySentAnInvitation') . '</a></li>';
         } else {
             if (!$show_full_profile) {
                 $html .= '<li><a class="btn-to-send-invitation" href="#" data-send-to="' . $user_id . '" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . '&nbsp;' . get_lang('SendInvitation') . '</a></li>';
             }
         }
         // Chat
         //@todo check if user is online and if it's a friend to show the chat link
         /*if (api_is_global_chat_enabled()) {
                         $user_name = $user_info['complete_name'];
         
                         if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) {
                             if ($user_id != api_get_user_id()) {
                                 //Only show chat if I'm available to talk
                                 if ($current_user_info['user_is_online_in_chat'] == 1) {
                                     $options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online_in_chat']."')");
                                     $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
                                     $html .= Display::tag('li',
                                         Display::url(
                                             $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
                                             'javascript:void(0);',
                                             $options
                                         )
                                     );
                                 }
                             }
                         } else {
                             if ($user_id != api_get_user_id()) {
                                 if ($current_user_info['user_is_online_in_chat'] == 1) {
                                     $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name));
                                     $options = array('onclick' => "javascript:chatNotYetWith('".$message."')");
                                     $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
                                     $html .= Display::tag('li',
                                         Display::url(
                                             $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
                                             'javascript:void(0);',
                                             $options
                                         )
                                     );
                                 }
                             }
                         }
                     }*/
         $html .= '</ul></div></div>';
         if ($show_full_profile && $user_id == intval(api_get_user_id())) {
             $personal_course_list = UserManager::get_personal_session_course_list($user_id);
             $course_list_code = array();
             $i = 1;
             if (is_array($personal_course_list)) {
                 foreach ($personal_course_list as $my_course) {
                     if ($i <= 10) {
                         $course_list_code[] = array('code' => $my_course['code']);
                     } else {
                         break;
                     }
                     $i++;
                 }
                 // To avoid repeated courses
                 $course_list_code = array_unique_dimensional($course_list_code);
             }
             // Announcements
             $my_announcement_by_user_id = intval($user_id);
             $announcements = array();
             foreach ($course_list_code as $course) {
                 $course_info = api_get_course_info($course['code']);
                 if (!empty($course_info)) {
                     $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id);
                     if (!empty($content)) {
                         $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']);
                         $announcements[] = Display::tag('li', $url);
                     }
                 }
             }
             if (!empty($announcements)) {
                 $html .= '<div class="social_menu_items">';
                 $html .= '<ul>';
                 foreach ($announcements as $announcement) {
                     $html .= $announcement;
                 }
                 $html .= '</ul>';
                 $html .= '</div>';
             }
         }
     }
     if ($show_delete_account_button) {
         $html .= '<div class="sidebar-nav"><ul><li>';
         $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php';
         $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url);
         $html .= '</li></ul></div>';
     }
     $html .= '';
     return $html;
 }
/* For licensing terms, see /license.txt */
/**
 * Responses to AJAX calls
 */
require_once '../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$isAllowedToEdit = api_is_allowed_to_edit();
$courseInfo = api_get_course_info();
switch ($action) {
    case 'delete_item':
        if ($isAllowedToEdit) {
            if (empty($_REQUEST['id'])) {
                return false;
            }
            if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
                return false;
            }
            $list = explode(',', $_REQUEST['id']);
            foreach ($list as $itemId) {
                if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $itemId)) {
                    AnnouncementManager::delete_announcement($courseInfo, $itemId);
                }
            }
        }
        break;
    default:
        echo '';
        break;
}
exit;