social.lib.php 27 KB

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