social.lib.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. // Relation type between users
  4. define('USERUNKNOW', '0');
  5. define('SOCIALUNKNOW', '1');
  6. define('SOCIALPARENT', '2');
  7. define('SOCIALFRIEND', '3');
  8. define('SOCIALGOODFRIEND','4');
  9. define('SOCIALENEMY', '5');
  10. define('SOCIALDELETED', '6');
  11. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  12. class SocialManager extends UserManager {
  13. private function __construct() {
  14. }
  15. /**
  16. * Allow to register contact to social network
  17. * @author isaac flores paz <isaac.flores@dokeos.com>
  18. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  19. * @param int user friend id
  20. * @param int user id
  21. * @param int relation between users see constants definition
  22. * @return void
  23. */
  24. public static function register_friend ($friend_id,$my_user_id,$relation_type) {
  25. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
  26. $friend_id = intval($friend_id);
  27. $my_user_id = intval($my_user_id);
  28. $relation_type = intval($relation_type);
  29. $sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' .$friend_id.' AND user_id='.$my_user_id;
  30. $result = Database::query($sql, __FILE__, __LINE__);
  31. $row = Database :: fetch_array($result, 'ASSOC');
  32. if ($row['count'] == 0) {
  33. $current_date=date('Y-m-d H:i:s');
  34. $sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . $friend_id . ','.$my_user_id.','.$relation_type.',"'.$current_date.'");';
  35. Database::query($sql_i, __FILE__, __LINE__);
  36. } else {
  37. $sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' . $friend_id . ' AND user_id='.$my_user_id;
  38. $result = Database::query($sql, __FILE__, __LINE__);
  39. $row = Database :: fetch_array($result, 'ASSOC');
  40. if ($row['count'] == 1) {
  41. $sql_i = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.$relation_type.' WHERE friend_user_id=' . $friend_id.' AND user_id='.$my_user_id;
  42. Database::query($sql_i, __FILE__, __LINE__);
  43. }
  44. }
  45. }
  46. /**
  47. * Deletes a contact
  48. * @param int user friend id
  49. * @param bool true will delete ALL friends relationship from $friend_id
  50. * @author isaac flores paz <isaac.flores@dokeos.com>
  51. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  52. */
  53. public static function removed_friend ($friend_id, $real_removed = false) {
  54. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
  55. $tbl_my_message = Database :: get_main_table(TABLE_MAIN_MESSAGE);
  56. $friend_id = intval($friend_id);
  57. if ($real_removed == true) {
  58. //Delete user friend
  59. $sql_delete_relationship1 = 'UPDATE ' . $tbl_my_friend .' SET relation_type='.SOCIALDELETED.' WHERE friend_user_id='.$friend_id;
  60. $sql_delete_relationship2 = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $friend_id;
  61. Database::query($sql_delete_relationship1, __FILE__, __LINE__);
  62. Database::query($sql_delete_relationship2, __FILE__, __LINE__);
  63. } else {
  64. $user_id=api_get_user_id();
  65. $sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE user_id=' . $user_id . ' AND relation_type<>6 AND friend_user_id='.$friend_id;
  66. $result = Database::query($sql, __FILE__, __LINE__);
  67. $row = Database :: fetch_array($result, 'ASSOC');
  68. if ($row['count'] == 1) {
  69. //Delete user friend
  70. $sql_i = 'UPDATE ' . $tbl_my_friend .' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $user_id.' AND friend_user_id='.$friend_id;
  71. $sql_j = 'UPDATE ' . $tbl_my_message.' SET msg_status=7 WHERE user_receiver_id=' . $user_id.' AND user_sender_id='.$friend_id;
  72. //Delete user
  73. $sql_ij = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $friend_id.' AND friend_user_id='.$user_id;
  74. $sql_ji = 'UPDATE ' . $tbl_my_message . ' SET msg_status=7 WHERE user_receiver_id=' . $friend_id.' AND user_sender_id='.$user_id;
  75. Database::query($sql_i, __FILE__, __LINE__);
  76. Database::query($sql_j, __FILE__, __LINE__);
  77. Database::query($sql_ij, __FILE__, __LINE__);
  78. Database::query($sql_ji, __FILE__, __LINE__);
  79. }
  80. }
  81. }
  82. /**
  83. * Allow to see contacts list
  84. * @author isaac flores paz <florespaz@bidsoftperu.com>
  85. * @return array
  86. */
  87. public static function show_list_type_friends () {
  88. $friend_relation_list=array();
  89. $count_list=0;
  90. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  91. $sql='SELECT id,title FROM '.$tbl_my_friend_relation_type.' WHERE id<>6 ORDER BY id ASC';
  92. $result=Database::query($sql,__FILE__,__LINE__);
  93. while ($row=Database::fetch_array($result,'ASSOC')) {
  94. $friend_relation_list[]=$row;
  95. }
  96. $count_list=count($friend_relation_list);
  97. if ($count_list==0) {
  98. $friend_relation_list[]=get_lang('UnkNow');
  99. } else {
  100. return $friend_relation_list;
  101. }
  102. }
  103. /**
  104. * Get relation type contact by name
  105. * @author isaac flores paz <florespaz@bidsoftperu.com>
  106. * @param string names of the kind of relation
  107. * @return int
  108. */
  109. public static function get_relation_type_by_name ($relation_type_name) {
  110. $list_type_friend=array();
  111. $list_type_friend=self::show_list_type_friends();
  112. foreach ($list_type_friend as $value_type_friend) {
  113. if (strtolower($value_type_friend['title'])==$relation_type_name) {
  114. return $value_type_friend['id'];
  115. }
  116. }
  117. }
  118. /**
  119. * Get the kind of relation between contacts
  120. * @author isaac flores paz <florespaz@bidsoftperu.com>
  121. * @param int user id
  122. * @param int user friend id
  123. * @param string
  124. */
  125. public static function get_relation_between_contacts ($user_id,$user_friend) {
  126. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  127. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
  128. $sql= 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt ' .
  129. 'WHERE rt.id=(SELECT uf.relation_type FROM '.$tbl_my_friend.' uf WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$user_friend).')';
  130. $res=Database::query($sql,__FILE__,__LINE__);
  131. $row=Database::fetch_array($res,'ASSOC');
  132. if (Database::num_rows($res)>0) {
  133. return $row['id'];
  134. } else {
  135. return USERUNKNOW;
  136. }
  137. }
  138. /**
  139. * get contacts id list
  140. * @author isaac flores paz <florespaz@bidsoftperu.com>
  141. * @param int user id
  142. * @param int group id
  143. * @param string name to search
  144. * @return array
  145. */
  146. public static function get_list_id_friends_by_user_id ($user_id,$id_group=null,$search_name=null) {
  147. $list_ids_friends=array();
  148. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
  149. $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
  150. $sql='SELECT friend_user_id FROM '.$tbl_my_friend.' WHERE relation_type<>6 AND friend_user_id<>'.((int)$user_id).' AND user_id='.((int)$user_id);
  151. if (isset($id_group) && $id_group>0) {
  152. $sql.=' AND relation_type='.$id_group;
  153. }
  154. if (isset($search_name) && is_string($search_name)===true) {
  155. $sql.=' AND friend_user_id IN (SELECT user_id FROM '.$tbl_my_user.' WHERE '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' like concat("%","'.Database::escape_string($search_name).'","%"));';
  156. }
  157. $res=Database::query($sql,__FILE__,__LINE__);
  158. while ($row=Database::fetch_array($res,'ASSOC')) {
  159. $list_ids_friends[]=$row;
  160. }
  161. return $list_ids_friends;
  162. }
  163. /**
  164. * get list web path of contacts by user id
  165. * @author isaac flores paz <florespaz@bidsoftperu.com>
  166. * @param int user id
  167. * @param int group id
  168. * @param string name to search
  169. * @param array
  170. */
  171. public static function get_list_path_web_by_user_id ($user_id,$id_group=null,$search_name=null) {
  172. $list_paths=array();
  173. $list_path_friend=array();
  174. $array_path_user=array();
  175. $combine_friend = array();
  176. $list_ids = self::get_list_id_friends_by_user_id ($user_id,$id_group,$search_name);
  177. if (is_array($list_ids)) {
  178. foreach ($list_ids as $values_ids) {
  179. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['friend_user_id'],'web',false,true);
  180. $combine_friend=array('id_friend'=>$list_ids,'path_friend'=>$list_path_image_friend);
  181. }
  182. }
  183. return $combine_friend;
  184. }
  185. /**
  186. * get web path of user invitate
  187. * @author isaac flores paz <florespaz@bidsoftperu.com>
  188. * @param int user id
  189. * @return array
  190. */
  191. public static function get_list_web_path_user_invitation_by_user_id ($user_id) {
  192. $list_paths=array();
  193. $list_path_friend=array();
  194. $list_ids = self::get_list_invitation_of_friends_by_user_id((int)$user_id);
  195. foreach ($list_ids as $values_ids) {
  196. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['user_sender_id'],'web',false,true);
  197. }
  198. return $list_path_image_friend;
  199. }
  200. /**
  201. * Sends an invitation to contacts
  202. * @author isaac flores paz <florespaz@bidsoftperu.com>
  203. * @author Julio Montya <gugli100@gmail.com> Cleaning code
  204. * @param int user id
  205. * @param int user friend id
  206. * @param string title of the message
  207. * @param string content of the message
  208. * @return boolean
  209. */
  210. public static function send_invitation_friend ($user_id,$friend_id,$message_title,$message_content) {
  211. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  212. $user_id = intval($user_id);
  213. $friend_id = intval($friend_id);
  214. $message_title = Database::escape_string($message_title);
  215. $message_content = Database::escape_string($message_content);
  216. $current_date = date('Y-m-d H:i:s',time());
  217. $status_invitation=5;//status of pending invitation
  218. $sql_exist='SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.($user_id).' AND user_receiver_id='.($friend_id).' AND msg_status IN(5,6,7);';
  219. $res_exist=Database::query($sql_exist,__FILE__,__LINE__);
  220. $row_exist=Database::fetch_array($res_exist,'ASSOC');
  221. if ($row_exist['count']==0) {
  222. $sql='INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content) VALUES('.$user_id.','.$friend_id.','.$status_invitation.',"'.$current_date.'","'.$message_title.'","'.$message_content.'")';
  223. Database::query($sql,__FILE__,__LINE__);
  224. return true;
  225. } elseif ($row_exist['count']==1) {
  226. //invitation already exist
  227. $sql_if_exist='SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status=7';
  228. $res_if_exist=Database::query($sql_if_exist,__FILE__,__LINE__);
  229. $row_if_exist=Database::fetch_array($res_if_exist,'ASSOC');
  230. if ($row_if_exist['count']==1) {
  231. $sql_if_exist_up='UPDATE '.$tbl_message.'SET msg_status=5 WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.';';
  232. Database::query($sql_if_exist_up,__FILE__,__LINE__);
  233. return true;
  234. } else {
  235. return false;
  236. }
  237. } else {
  238. return false;
  239. }
  240. }
  241. /**
  242. * Get number messages of the inbox
  243. * @author isaac flores paz <florespaz@bidsoftperu.com>
  244. * @param int user receiver id
  245. * @return int
  246. */
  247. public static function get_message_number_invitation_by_user_id ($user_receiver_id) {
  248. $status_invitation=5;//status of pending invitation
  249. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  250. $sql='SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.' WHERE user_receiver_id='.((int)$user_receiver_id).' AND msg_status=5';
  251. $res=Database::query($sql,__FILE__,__LINE__);
  252. $row=Database::fetch_array($res,'ASSOC');
  253. return $row['count_message_in_box'];
  254. }
  255. /**
  256. * Get invitation list received by user
  257. * @author isaac flores paz <florespaz@bidsoftperu.com>
  258. * @param int user id
  259. * @return array()
  260. */
  261. public static function get_list_invitation_of_friends_by_user_id ($user_id) {
  262. $list_friend_invitation=array();
  263. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  264. $sql='SELECT user_sender_id,send_date,title,content FROM '.$tbl_message.' WHERE user_receiver_id='.((int)$user_id).' AND msg_status = 5';
  265. $res=Database::query($sql,__FILE__,__LINE__);
  266. while ($row=Database::fetch_array($res,'ASSOC')) {
  267. $list_friend_invitation[]=$row;
  268. }
  269. return $list_friend_invitation;
  270. }
  271. /**
  272. * Get invitation list sent by user
  273. * @author Julio Montoya <gugli100@gmail.com>
  274. * @param int user id
  275. * @return array()
  276. */
  277. public static function get_list_invitation_sent_by_user_id ($user_id) {
  278. $list_friend_invitation=array();
  279. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  280. $sql='SELECT user_receiver_id, send_date,title,content FROM '.$tbl_message.' WHERE user_sender_id = '.intval($user_id).' AND msg_status = 5';
  281. $res=Database::query($sql,__FILE__,__LINE__);
  282. while ($row=Database::fetch_array($res,'ASSOC')) {
  283. $list_friend_invitation[$row['user_receiver_id']]=$row;
  284. }
  285. return $list_friend_invitation;
  286. }
  287. /**
  288. * allow accept invitation
  289. * @author isaac flores paz <florespaz@bidsoftperu.com>
  290. * @param int user sender id
  291. * @param int user receiver id
  292. * @return void()
  293. */
  294. public static function invitation_accepted ($user_send_id,$user_receiver_id) {
  295. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  296. $msg_status=6;// friend accepted
  297. $sql='UPDATE '.$tbl_message.' SET msg_status='.$msg_status.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';';
  298. Database::query($sql,__FILE__,__LINE__);
  299. }
  300. /**
  301. * allow deny invitation
  302. * @author isaac flores paz <florespaz@bidsoftperu.com>
  303. * @param int user sender id
  304. * @param int user receiver id
  305. * @return void()
  306. */
  307. public static function invitation_denied ($user_send_id,$user_receiver_id) {
  308. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  309. $msg_status=7;
  310. $sql='UPDATE '.$tbl_message.' SET msg_status='.$msg_status.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';';
  311. Database::query($sql,__FILE__,__LINE__);
  312. }
  313. /**
  314. * allow attach to group
  315. * @author isaac flores paz <florespaz@bidsoftperu.com>
  316. * @param int user to qualify
  317. * @param int kind of rating
  318. * @return void()
  319. */
  320. public static function qualify_friend ($id_friend_qualify,$type_qualify) {
  321. $tbl_user_friend=Database::get_main_table(TABLE_MAIN_USER_FRIEND);
  322. $user_id=api_get_user_id();
  323. $sql='UPDATE '.$tbl_user_friend.' SET relation_type='.((int)$type_qualify).' WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$id_friend_qualify).';';
  324. Database::query($sql,__FILE__,__LINE__);
  325. }
  326. /**
  327. * Sends invitations to friends
  328. * @author Isaac Flores Paz <isaac.flores.paz@gmail.com>
  329. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  330. * @param void
  331. * @return string message invitation
  332. */
  333. public static function send_invitation_friend_user ($userfriend_id,$subject_message='',$content_message='') {
  334. //$id_user_friend=array();
  335. $user_info = array();
  336. $user_info = api_get_user_info($userfriend_id);
  337. $succes = get_lang('MessageSentTo');
  338. $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
  339. if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) {
  340. $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message);
  341. if ($send_message) {
  342. echo Display::display_confirmation_message($succes,true);
  343. } else {
  344. echo Display::display_error_message($succes,true);
  345. }
  346. exit;
  347. } elseif (isset($userfriend_id) && !isset($subject_message)) {
  348. $count_is_true=false;
  349. $count_number_is_true=0;
  350. if (isset($userfriend_id) && $userfriend_id>0) {
  351. $message_title = get_lang('Invitation');
  352. $count_is_true = self::send_invitation_friend(api_get_user_id(),$userfriend_id, $message_title, $content_message);
  353. if ($count_is_true) {
  354. echo Display::display_normal_message(get_lang('InvitationHasBeenSent'));
  355. }else {
  356. echo Display::display_error_message(get_lang('YouAlreadySentAnInvitation'));
  357. }
  358. }
  359. }
  360. }
  361. /**
  362. * Get user's feeds
  363. * @param int User ID
  364. * @param int Limit of posts per feed
  365. * @return string HTML section with all feeds included
  366. * @author Yannick Warnier
  367. * @since Dokeos 1.8.6.1
  368. */
  369. function get_user_feeds($user, $limit=5) {
  370. if (!function_exists('fetch_rss')) { return '';}
  371. $fields = UserManager::get_extra_fields();
  372. $feed_fields = array();
  373. $feeds = array();
  374. $feed = UserManager::get_extra_user_data_by_field($user,'rssfeeds');
  375. if(empty($feed)) { return ''; }
  376. $feeds = split(';',$feed['rssfeeds']);
  377. if (count($feeds)==0) { return ''; }
  378. foreach ($feeds as $url) {
  379. if (empty($url)) { continue; }
  380. $rss = fetch_rss($url);
  381. $res .= '<h2>'.$rss->channel['title'].'</h2>';
  382. $res .= '<div class="social-rss-channel-items">';
  383. $i = 1;
  384. foreach ($rss->items as $item) {
  385. if ($limit>=0 and $i>$limit) {break;}
  386. $res .= '<h3><a href="'.$item['link'].'">'.$item['title'].'</a></h3>';
  387. $res .= '<div class="social-rss-item-date">'.api_get_datetime($item['date_timestamp']).'</div>';
  388. $res .= '<div class="social-rss-item-content">'.$item['description'].'</div><br />';
  389. $i++;
  390. }
  391. $res .= '</div>';
  392. }
  393. return $res;
  394. }
  395. /**
  396. * Helper functions definition
  397. */
  398. function get_logged_user_course_html($my_course, $count) {
  399. global $nosession;
  400. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  401. global $now, $date_start, $date_end;
  402. }
  403. //initialise
  404. $result = '';
  405. // Table definitions
  406. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  407. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  408. $course_database = $my_course['db'];
  409. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  410. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  411. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  412. $user_id = api_get_user_id();
  413. $course_system_code = $my_course['k'];
  414. $course_visual_code = $my_course['c'];
  415. $course_title = $my_course['i'];
  416. $course_directory = $my_course['d'];
  417. $course_teacher = $my_course['t'];
  418. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  419. $course_info = Database :: get_course_info($course_system_code);
  420. //error_log(print_r($course_info,true));
  421. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  422. $course_visibility = $course_access_settings['visibility'];
  423. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  424. //function logic - act on the data
  425. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  426. if ($is_virtual_course) {
  427. // If the current user is also subscribed in the real course to which this
  428. // virtual course is linked, we don't need to display the virtual course entry in
  429. // the course list - it is combined with the real course entry.
  430. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  431. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  432. if ($is_subscribed_in_target_course) {
  433. return; //do not display this course entry
  434. }
  435. }
  436. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  437. if ($has_virtual_courses) {
  438. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  439. $course_display_title = $return_result['title'];
  440. $course_display_code = $return_result['code'];
  441. } else {
  442. $course_display_title = $course_title;
  443. $course_display_code = $course_visual_code;
  444. }
  445. $s_course_status=$my_course['s'];
  446. $s_htlm_status_icon="";
  447. if ($s_course_status==1) {
  448. $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher'));
  449. }
  450. if ($s_course_status==2) {
  451. $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach'));
  452. }
  453. if ($s_course_status==5) {
  454. $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student'));
  455. }
  456. //display course entry
  457. $result .= '<div id="div_'.$count.'">';
  458. //$result .= '<a id="btn_'.$count.'" href="#" onclick="toogle_function(this,\''.$course_database.'\')">';
  459. $result .= '<h2><img src="../img/nolines_plus.gif" id="btn_'.$count.'" onclick="toogle_function(this,\''.$course_database.'\' )">';
  460. $result .= $s_htlm_status_icon;
  461. //show a hyperlink to the course, unless the course is closed and user is not course admin
  462. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  463. $result .= '<a href="javascript:void(0)" id="ln_'.$count.'" onclick=toogle_function(this,\''.$course_database.'\');>&nbsp;'.$course_title.'</a></h2>';
  464. /*
  465. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  466. if(empty($my_course['id_session'])) {
  467. $my_course['id_session'] = 0;
  468. }
  469. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  470. //$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  471. $result .= '<a href="#">'.$course_display_title.'</a>';
  472. }
  473. } else {
  474. //$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  475. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  476. }*/
  477. } else {
  478. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  479. }
  480. // show the course_code and teacher if chosen to display this
  481. // we dont need this!
  482. /*
  483. if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') {
  484. $result .= '<br />';
  485. }
  486. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  487. $result .= $course_display_code;
  488. }
  489. if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') {
  490. $result .= ' &ndash; ';
  491. }
  492. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  493. $result .= $course_teacher;
  494. if(!empty($course_teacher_email)) {
  495. $result .= ' ('.$course_teacher_email.')';
  496. }
  497. }
  498. */
  499. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  500. // display the what's new icons
  501. // $result .= show_notification($my_course);
  502. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  503. reset($digest);
  504. $result .= '<ul>';
  505. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  506. $result .= '<li>';
  507. if ($orderKey[1] == 'keyTools') {
  508. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  509. $result .= "$toolsList[$key2][\"name\"]</a>";
  510. } else {
  511. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  512. }
  513. $result .= '</li>';
  514. $result .= '<ul>';
  515. reset($digest[$thisCourseSysCode][$key2]);
  516. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  517. $result .= '<li>';
  518. if ($orderKey[2] == 'keyTools') {
  519. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  520. $result .= "$toolsList[$key3][\"name\"]</a>";
  521. } else {
  522. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  523. }
  524. $result .= '<ul compact="compact">';
  525. reset($digest[$thisCourseSysCode][$key2][$key3]);
  526. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  527. $result .= '<li>';
  528. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  529. $result .= '</li>';
  530. }
  531. $result .= '</ul>';
  532. $result .= '</li>';
  533. }
  534. $result .= '</ul>';
  535. $result .= '</li>';
  536. }
  537. $result .= '</ul>';
  538. }
  539. $result .= '</li>';
  540. $result .= '</div>';
  541. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  542. $session = '';
  543. $active = false;
  544. if (!empty($my_course['session_name'])) {
  545. // Request for the name of the general coach
  546. $sql = 'SELECT lastname, firstname
  547. FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu
  548. ON ts.id_coach = tu.user_id
  549. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  550. $rs = Database::query($sql, __FILE__, __LINE__);
  551. $sessioncoach = Database::store_result($rs);
  552. $sessioncoach = $sessioncoach[0];
  553. $session = array();
  554. $session['title'] = $my_course['session_name'];
  555. if ( $my_course['date_start']=='0000-00-00' ) {
  556. $session['dates'] = get_lang('WithoutTimeLimits');
  557. if ( api_get_setting('show_session_coach') === 'true' ) {
  558. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  559. }
  560. $active = true;
  561. } else {
  562. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  563. if ( api_get_setting('show_session_coach') === 'true' ) {
  564. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  565. }
  566. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  567. }
  568. }
  569. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
  570. } else {
  571. $output = array ($my_course['user_course_cat'], $result);
  572. }
  573. //$my_course['creation_date'];
  574. return $output;
  575. }
  576. public static function show_social_menu() {
  577. echo '<div class="actions">';
  578. echo '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('shared_profile.png').' '.get_lang('ViewMySharedProfile').'</a>';
  579. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php?f=social">'.Display::return_icon('inbox.png').' '.get_lang('Messages').'</a>';
  580. echo '<a href="'.api_get_path(WEB_PATH).'main/social/friends.php">'.Display::return_icon('lp_users.png').' '.get_lang('Friends').'</a>';
  581. echo '<a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('lp_users.png').' '.get_lang('Invitations').'</a>';
  582. echo '<a href="'.api_get_path(WEB_PATH).'main/social/groups.php">'.Display::return_icon('group.gif').' '.get_lang('MyGroups').'</a>';
  583. echo '<a href="'.api_get_path(WEB_PATH).'main/social/search.php">'.Display::return_icon('search.gif').' '.get_lang('Search').'</a>';
  584. echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php?show=1">'.Display::return_icon('edit.gif').' '.get_lang('EditProfile').'</a>';
  585. /*
  586. echo '<span style="float:right; padding-top:7px;">'.
  587. '<a href="/main/auth/profile.php?show=1">'.Display::return_icon('edit.gif').' '.get_lang('Configuration').'</a>';
  588. '</span>';
  589. */
  590. echo '</div>';
  591. }
  592. }