social.lib.php 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class SocialManager
  5. *
  6. * This class provides methods for the social network management.
  7. * Include/require it in your code to use its features.
  8. *
  9. * @package chamilo.social
  10. */
  11. class SocialManager extends UserManager
  12. {
  13. /**
  14. * Constructor
  15. */
  16. public function __construct()
  17. {
  18. }
  19. /**
  20. * Allow to see contacts list
  21. * @author isaac flores paz
  22. * @return array
  23. */
  24. public static function show_list_type_friends()
  25. {
  26. $friend_relation_list = array();
  27. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  28. $sql = 'SELECT id,title FROM '.$tbl_my_friend_relation_type.'
  29. WHERE id<>6 ORDER BY id ASC';
  30. $result = Database::query($sql);
  31. while ($row = Database::fetch_array($result, 'ASSOC')) {
  32. $friend_relation_list[] = $row;
  33. }
  34. $count_list = count($friend_relation_list);
  35. if ($count_list == 0) {
  36. $friend_relation_list[] = get_lang('Unknown');
  37. } else {
  38. return $friend_relation_list;
  39. }
  40. }
  41. /**
  42. * Get relation type contact by name
  43. * @param string names of the kind of relation
  44. * @return int
  45. * @author isaac flores paz
  46. */
  47. public static function get_relation_type_by_name($relation_type_name)
  48. {
  49. $list_type_friend = self::show_list_type_friends();
  50. foreach ($list_type_friend as $value_type_friend) {
  51. if (strtolower($value_type_friend['title']) == $relation_type_name) {
  52. return $value_type_friend['id'];
  53. }
  54. }
  55. }
  56. /**
  57. * Get the kind of relation between contacts
  58. * @param int user id
  59. * @param int user friend id
  60. * @param string
  61. * @author isaac flores paz
  62. */
  63. public static function get_relation_between_contacts($user_id, $user_friend)
  64. {
  65. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  66. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  67. $sql = 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt
  68. WHERE rt.id = (
  69. SELECT uf.relation_type FROM '.$tbl_my_friend.' uf
  70. WHERE
  71. user_id='.((int) $user_id).' AND
  72. friend_user_id='.((int) $user_friend).' AND
  73. uf.relation_type <> '.USER_RELATION_TYPE_RRHH.'
  74. LIMIT 1
  75. )';
  76. $res = Database::query($sql);
  77. if (Database::num_rows($res) > 0) {
  78. $row = Database::fetch_array($res, 'ASSOC');
  79. return $row['id'];
  80. } else {
  81. return USER_UNKNOW;
  82. }
  83. }
  84. /**
  85. * Gets friends id list
  86. * @param int user id
  87. * @param int group id
  88. * @param string name to search
  89. * @param bool true will load firstname, lastname, and image name
  90. * @return array
  91. * @author Julio Montoya <gugli100@gmail.com> Cleaning code, function renamed, $load_extra_info option added
  92. * @author isaac flores paz
  93. */
  94. public static function get_friends($user_id, $id_group = null, $search_name = null, $load_extra_info = true)
  95. {
  96. $list_ids_friends = array();
  97. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  98. $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
  99. $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.'
  100. WHERE
  101. relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND
  102. friend_user_id<>'.((int) $user_id).' AND
  103. user_id='.((int) $user_id);
  104. if (isset($id_group) && $id_group > 0) {
  105. $sql.=' AND relation_type='.$id_group;
  106. }
  107. if (isset($search_name)) {
  108. $search_name = trim($search_name);
  109. $search_name = str_replace(' ', '', $search_name);
  110. $sql.=' AND friend_user_id IN (
  111. SELECT user_id FROM '.$tbl_my_user.'
  112. WHERE
  113. firstName LIKE "%'.Database::escape_string($search_name).'%" OR
  114. lastName LIKE "%'.Database::escape_string($search_name).'%" OR
  115. '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%")
  116. ) ';
  117. }
  118. $res = Database::query($sql);
  119. while ($row = Database::fetch_array($res, 'ASSOC')) {
  120. if ($load_extra_info) {
  121. $my_user_info = api_get_user_info($row['friend_user_id']);
  122. $list_ids_friends[] = array(
  123. 'friend_user_id' => $row['friend_user_id'],
  124. 'firstName' => $my_user_info['firstName'],
  125. 'lastName' => $my_user_info['lastName'],
  126. 'username' => $my_user_info['username'],
  127. 'image' => $my_user_info['avatar']
  128. );
  129. } else {
  130. $list_ids_friends[] = $row;
  131. }
  132. }
  133. return $list_ids_friends;
  134. }
  135. /**
  136. * get web path of user invitate
  137. * @author isaac flores paz
  138. * @author Julio Montoya setting variable array
  139. * @param int user id
  140. *
  141. * @return array
  142. */
  143. public static function get_list_web_path_user_invitation_by_user_id($user_id)
  144. {
  145. $list_ids = self::get_list_invitation_of_friends_by_user_id($user_id);
  146. $list = array();
  147. foreach ($list_ids as $values_ids) {
  148. $list[] = UserManager::get_user_picture_path_by_id(
  149. $values_ids['user_sender_id'],
  150. 'web'
  151. );
  152. }
  153. return $list;
  154. }
  155. /**
  156. * Sends an invitation to contacts
  157. * @param int user id
  158. * @param int user friend id
  159. * @param string title of the message
  160. * @param string content of the message
  161. * @return boolean
  162. * @author isaac flores paz
  163. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  164. */
  165. public static function send_invitation_friend($user_id, $friend_id, $message_title, $message_content)
  166. {
  167. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  168. $user_id = intval($user_id);
  169. $friend_id = intval($friend_id);
  170. //Just in case we replace the and \n and \n\r while saving in the DB
  171. $message_content = str_replace(array("\n", "\n\r"), '<br />', $message_content);
  172. $clean_message_content = Database::escape_string($message_content);
  173. $now = api_get_utc_datetime();
  174. $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.'
  175. WHERE
  176. user_sender_id='.$user_id.' AND
  177. user_receiver_id='.$friend_id.' AND
  178. msg_status IN(5,6,7);
  179. ';
  180. $res_exist = Database::query($sql);
  181. $row_exist = Database::fetch_array($res_exist, 'ASSOC');
  182. if ($row_exist['count'] == 0) {
  183. $params = [
  184. 'user_sender_id' => $user_id,
  185. 'user_receiver_id' => $friend_id,
  186. 'msg_status' => MESSAGE_STATUS_INVITATION_PENDING,
  187. 'send_date' => $now,
  188. 'title' => $message_title,
  189. 'content' => $message_content,
  190. ];
  191. Database::insert($tbl_message, $params);
  192. $sender_info = api_get_user_info($user_id);
  193. $notification = new Notification();
  194. $notification->save_notification(
  195. Notification::NOTIFICATION_TYPE_INVITATION,
  196. array($friend_id),
  197. $message_title,
  198. $message_content,
  199. $sender_info
  200. );
  201. return true;
  202. } else {
  203. // invitation already exist
  204. $sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.'
  205. WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7';
  206. $res_if_exist = Database::query($sql);
  207. $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC');
  208. if ($row_if_exist['count'] == 1) {
  209. $sql = 'UPDATE '.$tbl_message.' SET
  210. msg_status=5, content = "'.$clean_message_content.'"
  211. WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 ';
  212. Database::query($sql);
  213. return true;
  214. } else {
  215. return false;
  216. }
  217. }
  218. }
  219. /**
  220. * Get number messages of the inbox
  221. * @author isaac flores paz
  222. * @param int user receiver id
  223. * @return int
  224. */
  225. public static function get_message_number_invitation_by_user_id($user_receiver_id)
  226. {
  227. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  228. $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.'
  229. WHERE
  230. user_receiver_id='.intval($user_receiver_id).' AND
  231. msg_status='.MESSAGE_STATUS_INVITATION_PENDING;
  232. $res = Database::query($sql);
  233. $row = Database::fetch_array($res, 'ASSOC');
  234. return $row['count_message_in_box'];
  235. }
  236. /**
  237. * Get invitation list received by user
  238. * @author isaac flores paz
  239. * @param int user id
  240. * @return array
  241. */
  242. public static function get_list_invitation_of_friends_by_user_id($user_id)
  243. {
  244. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  245. $sql = 'SELECT user_sender_id, send_date, title, content
  246. FROM '.$tbl_message.'
  247. WHERE
  248. user_receiver_id = '.intval($user_id).' AND
  249. msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  250. $res = Database::query($sql);
  251. $list_friend_invitation = array();
  252. while ($row = Database::fetch_array($res, 'ASSOC')) {
  253. $list_friend_invitation[] = $row;
  254. }
  255. return $list_friend_invitation;
  256. }
  257. /**
  258. * Get invitation list sent by user
  259. * @author Julio Montoya <gugli100@gmail.com>
  260. * @param int user id
  261. * @return array()
  262. */
  263. public static function get_list_invitation_sent_by_user_id($user_id)
  264. {
  265. $list_friend_invitation = array();
  266. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  267. $sql = 'SELECT user_receiver_id, send_date,title,content
  268. FROM '.$tbl_message.'
  269. WHERE user_sender_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  270. $res = Database::query($sql);
  271. while ($row = Database::fetch_array($res, 'ASSOC')) {
  272. $list_friend_invitation[$row['user_receiver_id']] = $row;
  273. }
  274. return $list_friend_invitation;
  275. }
  276. /**
  277. * Accepts invitation
  278. * @param int $user_send_id
  279. * @param int $user_receiver_id
  280. * @author isaac flores paz
  281. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  282. */
  283. public static function invitation_accepted($user_send_id, $user_receiver_id)
  284. {
  285. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  286. $sql = "UPDATE $tbl_message
  287. SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED."
  288. WHERE
  289. user_sender_id = ".((int) $user_send_id)." AND
  290. user_receiver_id=".((int) $user_receiver_id)." AND
  291. msg_status = ".MESSAGE_STATUS_INVITATION_PENDING;
  292. Database::query($sql);
  293. }
  294. /**
  295. * Denies invitation
  296. * @param int user sender id
  297. * @param int user receiver id
  298. * @author isaac flores paz
  299. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  300. */
  301. public static function invitation_denied($user_send_id, $user_receiver_id)
  302. {
  303. $tbl_message = Database::get_main_table(TABLE_MESSAGE);
  304. $sql = 'DELETE FROM '.$tbl_message.'
  305. WHERE
  306. user_sender_id = '.((int) $user_send_id).' AND
  307. user_receiver_id='.((int) $user_receiver_id).' AND
  308. msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  309. Database::query($sql);
  310. }
  311. /**
  312. * allow attach to group
  313. * @author isaac flores paz
  314. * @param int user to qualify
  315. * @param int kind of rating
  316. * @return void()
  317. */
  318. public static function qualify_friend($id_friend_qualify, $type_qualify)
  319. {
  320. $tbl_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
  321. $user_id = api_get_user_id();
  322. $sql = 'UPDATE '.$tbl_user_friend.' SET relation_type='.((int) $type_qualify).'
  323. WHERE user_id = '.((int) $user_id).' AND friend_user_id='.(int) $id_friend_qualify;
  324. Database::query($sql);
  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. {
  335. global $charset;
  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. Display::addFlash(
  343. Display::display_confirmation_message($succes, true, true)
  344. );
  345. } else {
  346. Display::addFlash(
  347. Display::display_error_message(get_lang('ErrorSendingMessage'), true, true)
  348. );
  349. }
  350. return false;
  351. } elseif (isset($userfriend_id) && !isset($subject_message)) {
  352. $count_is_true = false;
  353. if (isset($userfriend_id) && $userfriend_id > 0) {
  354. $message_title = get_lang('Invitation');
  355. $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message);
  356. if ($count_is_true) {
  357. Display::addFlash(
  358. Display::display_confirmation_message(
  359. api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES, $charset),
  360. false,
  361. true
  362. )
  363. );
  364. } else {
  365. Display::addFlash(
  366. Display::display_warning_message(
  367. api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES, $charset),
  368. false,
  369. true
  370. )
  371. );
  372. }
  373. }
  374. }
  375. }
  376. /**
  377. * Get user's feeds
  378. * @param int User ID
  379. * @param int Limit of posts per feed
  380. * @return string HTML section with all feeds included
  381. * @author Yannick Warnier
  382. * @since Dokeos 1.8.6.1
  383. */
  384. public static function get_user_feeds($user, $limit = 5)
  385. {
  386. if (!function_exists('fetch_rss')) {
  387. return '';
  388. }
  389. $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds');
  390. if (empty($feed)) {
  391. return '';
  392. }
  393. $feeds = explode(';', $feed['rssfeeds']);
  394. if (count($feeds) == 0) {
  395. return '';
  396. }
  397. $res = '';
  398. foreach ($feeds as $url) {
  399. if (empty($url)) {
  400. continue;
  401. }
  402. $rss = @fetch_rss($url);
  403. $i = 1;
  404. if (!empty($rss->items)) {
  405. $icon_rss = '';
  406. if (!empty($feed)) {
  407. $icon_rss = Display::url(
  408. Display::return_icon('social_rss.png', '', array(), 22),
  409. Security::remove_XSS($feed['rssfeeds']),
  410. array('target' => '_blank')
  411. );
  412. }
  413. $res .= '<h3 class="title-rss">'.$icon_rss.' '.$rss->channel['title'].'</h3>';
  414. $res .= '<div class="rss-items">';
  415. foreach ($rss->items as $item) {
  416. if ($limit >= 0 and $i > $limit) {
  417. break;
  418. }
  419. $res .= '<h4 class="rss-title"><a href="'.$item['link'].'">'.$item['title'].'</a></h4>';
  420. $res .= '<div class="rss-date">'.api_get_local_time($item['date_timestamp']).'</div>';
  421. $res .= '<div class="rss-content"><p>'.$item['description'].'</p></div>';
  422. $i++;
  423. }
  424. $res .= '</div>';
  425. }
  426. }
  427. return $res;
  428. }
  429. /**
  430. * Helper functions definition
  431. */
  432. public static function get_logged_user_course_html($my_course, $count)
  433. {
  434. $result = '';
  435. // Table definitions
  436. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  437. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  438. $course_code = $my_course['code'];
  439. $course_directory = $my_course['course_info']['directory'];
  440. $course_title = $my_course['course_info']['title'];
  441. $course_access_settings = CourseManager :: get_access_settings($course_code);
  442. $course_visibility = $course_access_settings['visibility'];
  443. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_code);
  444. //$valor = api_get_settings_params();
  445. $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path
  446. if (api_get_setting('course_images_in_courses_list') === 'true') {
  447. if (file_exists($course_path.'/course-pic85x85.png')) {
  448. $image = $my_course['course_info']['course_image'];
  449. $imageCourse = Display::img($image, $course_title, array('class'=>'img-course'));
  450. } else {
  451. $imageCourse = Display::return_icon('session_default_small.png', $course_title, array('class' => 'img-course'));
  452. }
  453. } else {
  454. $imageCourse = Display::return_icon('course.png', get_lang('Course'), array('class' => 'img-default'));
  455. }
  456. //display course entry
  457. if (api_get_setting('course_images_in_courses_list') === 'true') {
  458. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">';
  459. } else {
  460. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">';
  461. }
  462. $result .= $imageCourse;
  463. //show a hyperlink to the course, unless the course is closed and user is not course admin
  464. if ($course_visibility != COURSE_VISIBILITY_HIDDEN &&
  465. ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)
  466. ) {
  467. $result .= '<span class="title">' . $course_title . '<span>';
  468. } else {
  469. $result .= $course_title." "." ".get_lang('CourseClosed')."";
  470. }
  471. $result .= '</li>';
  472. $session = '';
  473. if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) {
  474. // Request for the name of the general coach
  475. $sql = 'SELECT lastname, firstname
  476. FROM '.$tbl_session.' ts
  477. LEFT JOIN '.$main_user_table.' tu
  478. ON ts.id_coach = tu.user_id
  479. WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1';
  480. $rs = Database::query($sql);
  481. $sessioncoach = Database::store_result($rs);
  482. $sessioncoach = $sessioncoach[0];
  483. $session = array();
  484. $session['title'] = $my_course['session_name'];
  485. if ($my_course['access_start_date'] == '0000-00-00') {
  486. $session['dates'] = get_lang('WithoutTimeLimits');
  487. if (api_get_setting('show_session_coach') === 'true') {
  488. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  489. }
  490. } else {
  491. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date'];
  492. if (api_get_setting('show_session_coach') === 'true') {
  493. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  494. }
  495. }
  496. }
  497. $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
  498. $output = array(
  499. $my_course['user_course_cat'],
  500. $result,
  501. $my_course['id_session'],
  502. $session,
  503. );
  504. return $output;
  505. }
  506. /**
  507. * Shows the avatar block in social pages
  508. *
  509. * @param string highlight link possible values:
  510. * group_add,
  511. * home,
  512. * messages,
  513. * messages_inbox,
  514. * messages_compose,
  515. * messages_outbox,
  516. * invitations,
  517. * shared_profile,
  518. * friends,
  519. * groups search
  520. * @param int group id
  521. * @param int user id
  522. *
  523. */
  524. public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0)
  525. {
  526. if (empty($user_id)) {
  527. $user_id = api_get_user_id();
  528. }
  529. $show_groups = array(
  530. 'groups',
  531. 'group_messages',
  532. 'messages_list',
  533. 'group_add',
  534. 'mygroups',
  535. 'group_edit',
  536. 'member_list',
  537. 'invite_friends',
  538. 'waiting_list',
  539. 'browse_groups'
  540. );
  541. $template = new Template(null, false, false, false, false, false);
  542. if (in_array($show, $show_groups) && !empty($group_id)) {
  543. // Group image
  544. $userGroup = new UserGroup();
  545. $group_info = $userGroup->get($group_id);
  546. $userGroupImage = $userGroup->get_picture_group(
  547. $group_id,
  548. $group_info['picture'],
  549. 160,
  550. GROUP_IMAGE_SIZE_BIG
  551. );
  552. $template->assign('show_group', true);
  553. $template->assign('group_id', $group_id);
  554. $template->assign('user_group_image', $userGroupImage);
  555. $template->assign('user_group', $group_info);
  556. $template->assign(
  557. 'user_is_group_admin',
  558. $userGroup->is_group_admin(
  559. $group_id,
  560. api_get_user_id()
  561. )
  562. );
  563. } else {
  564. $template->assign('show_user', true);
  565. $template->assign(
  566. 'user_image',
  567. [
  568. 'big' => UserManager::getUserPicture(
  569. $user_id,
  570. USER_IMAGE_SIZE_BIG
  571. ),
  572. 'normal' => UserManager::getUserPicture(
  573. $user_id,
  574. USER_IMAGE_SIZE_MEDIUM
  575. )
  576. ]
  577. );
  578. }
  579. $skillBlock = $template->get_template('social/avatar_block.tpl');
  580. return $template->fetch($skillBlock);
  581. }
  582. /**
  583. * Shows the right menu of the Social Network tool
  584. *
  585. * @param string $show highlight link possible values:
  586. * group_add,
  587. * home,
  588. * messages,
  589. * messages_inbox,
  590. * messages_compose ,
  591. * messages_outbox,
  592. * invitations,
  593. * shared_profile,
  594. * friends,
  595. * groups search
  596. * @param int $group_id group id
  597. * @param int $user_id user id
  598. * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  599. * @param bool $show_delete_account_button
  600. *
  601. */
  602. public static function show_social_menu(
  603. $show = '',
  604. $group_id = 0,
  605. $user_id = 0,
  606. $show_full_profile = false,
  607. $show_delete_account_button = false
  608. ) {
  609. if (empty($user_id)) {
  610. $user_id = api_get_user_id();
  611. }
  612. $usergroup = new UserGroup();
  613. $user_info = api_get_user_info($user_id, true);
  614. $current_user_id = api_get_user_id();
  615. $current_user_info = api_get_user_info($current_user_id, true);
  616. if ($current_user_id == $user_id) {
  617. $user_friend_relation = null;
  618. } else {
  619. $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
  620. }
  621. $show_groups = array(
  622. 'groups',
  623. 'group_messages',
  624. 'messages_list',
  625. 'group_add',
  626. 'mygroups',
  627. 'group_edit',
  628. 'member_list',
  629. 'invite_friends',
  630. 'waiting_list',
  631. 'browse_groups'
  632. );
  633. // get count unread message and total invitations
  634. $count_unread_message = MessageManager::get_number_of_messages(true);
  635. $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
  636. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  637. $group_pending_invitations = $usergroup->get_groups_by_user(
  638. api_get_user_id(),
  639. GROUP_USER_PERMISSION_PENDING_INVITATION,
  640. false
  641. );
  642. $group_pending_invitations = count($group_pending_invitations);
  643. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  644. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : '');
  645. $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL);
  646. $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL);
  647. $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL);
  648. $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), '', ICON_SIZE_SMALL);
  649. $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL);
  650. $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL);
  651. $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
  652. $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), '', ICON_SIZE_SMALL);
  653. $html = '';
  654. $active = null;
  655. if (!in_array(
  656. $show,
  657. array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends')
  658. )) {
  659. $html .= '<div class="panel panel-default sidebar-nav">';
  660. $html .= '<div class="panel-body">';
  661. $html .= '<ul class="nav nav-pills nav-stacked">';
  662. $active = $show == 'home' ? 'active' : null;
  663. $html .= '
  664. <li class="home-icon ' . $active . '">
  665. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  666. ' . $homeIcon . ' ' . get_lang('Home') . '
  667. </a>
  668. </li>';
  669. $active = $show == 'messages' ? 'active' : null;
  670. $html .= '
  671. <li class="messages-icon ' . $active . '">
  672. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  673. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  674. </a>
  675. </li>';
  676. //Invitations
  677. $active = $show == 'invitations' ? 'active' : null;
  678. $html .= '
  679. <li class="invitations-icon ' . $active . '">
  680. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  681. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  682. </a>
  683. </li>';
  684. //Shared profile and groups
  685. $active = $show == 'shared_profile' ? 'active' : null;
  686. $html .= '
  687. <li class="shared-profile-icon' . $active . '">
  688. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  689. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  690. </a>
  691. </li>';
  692. $active = $show == 'friends' ? 'active' : null;
  693. $html .= '
  694. <li class="friends-icon ' . $active . '">
  695. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  696. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  697. </a>
  698. </li>';
  699. $active = $show == 'browse_groups' ? 'active' : null;
  700. $html .= '
  701. <li class="browse-groups-icon ' . $active . '">
  702. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  703. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  704. </a>
  705. </li>';
  706. //Search users
  707. $active = $show == 'search' ? 'active' : null;
  708. $html .= '
  709. <li class="search-icon ' . $active . '">
  710. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  711. ' . $searchIcon . ' ' . get_lang('Search') . '
  712. </a>
  713. </li>';
  714. //My files
  715. $active = $show == 'myfiles' ? 'active' : null;
  716. $html .= '
  717. <li class="myfiles-icon ' . $active . '">
  718. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  719. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  720. </a>
  721. </li>';
  722. $html .='</ul></div></div>';
  723. }
  724. if (in_array($show, $show_groups) && !empty($group_id)) {
  725. $html .= $usergroup->show_group_column_information(
  726. $group_id,
  727. api_get_user_id(),
  728. $show
  729. );
  730. }
  731. if ($show == 'shared_profile') {
  732. $html .= '<div class="panel panel-default sidebar-nav">';
  733. $html .= '<div class="panel-body">';
  734. $html .= '<ul class="nav nav-pills nav-stacked">';
  735. // My own profile
  736. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  737. $html .= '
  738. <li class="home-icon ' . $active . '">
  739. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  740. ' . $homeIcon . ' ' . get_lang('Home') . '
  741. </a>
  742. </li>
  743. <li class="messages-icon ' . $active . '">
  744. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  745. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  746. </a>
  747. </li>';
  748. $active = $show == 'invitations' ? 'active' : null;
  749. $html .= '
  750. <li class="invitations-icon' . $active . '">
  751. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  752. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  753. </a>
  754. </li>';
  755. $html .= '
  756. <li class="shared-profile-icon active">
  757. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  758. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  759. </a>
  760. </li>
  761. <li class="friends-icon">
  762. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  763. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  764. </a>
  765. </li>
  766. <li class="browse-groups-icon">
  767. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  768. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  769. </a>
  770. </li>';
  771. $active = $show == 'search' ? 'active' : null;
  772. $html .= '
  773. <li class="search-icon ' . $active . '">
  774. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  775. ' . $searchIcon . ' ' . get_lang('Search') . '
  776. </a>
  777. </li>';
  778. $active = $show == 'myfiles' ? 'active' : null;
  779. $html .= '
  780. <li class="myfiles-icon ' . $active . '">
  781. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  782. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  783. </a>
  784. </li>';
  785. }
  786. // My friend profile.
  787. if ($user_id != api_get_user_id()) {
  788. $sendMessageText = get_lang('SendMessage');
  789. $sendMessageIcon = Display::return_icon(
  790. 'compose_message.png',
  791. $sendMessageText
  792. );
  793. $sendMesssageUrl = api_get_path(WEB_AJAX_PATH)
  794. . 'user_manager.ajax.php?'
  795. . http_build_query([
  796. 'a' => 'get_user_popup',
  797. 'user_id' => $user_id
  798. ]);
  799. $html .= '<li>';
  800. $html .= Display::url(
  801. "$sendMessageIcon $sendMessageText",
  802. $sendMesssageUrl,
  803. [
  804. 'class' => 'ajax',
  805. 'title' => $sendMessageText,
  806. 'data-title' => $sendMessageText
  807. ]
  808. );
  809. $html .= '</li>';
  810. }
  811. // Check if I already sent an invitation message
  812. $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
  813. if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
  814. $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>';
  815. } else {
  816. if (!$show_full_profile) {
  817. $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>';
  818. }
  819. }
  820. // Chat
  821. //@todo check if user is online and if it's a friend to show the chat link
  822. /*if (api_is_global_chat_enabled()) {
  823. $user_name = $user_info['complete_name'];
  824. if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) {
  825. if ($user_id != api_get_user_id()) {
  826. //Only show chat if I'm available to talk
  827. if ($current_user_info['user_is_online_in_chat'] == 1) {
  828. $options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online_in_chat']."')");
  829. $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'));
  830. $html .= Display::tag('li',
  831. Display::url(
  832. $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
  833. 'javascript:void(0);',
  834. $options
  835. )
  836. );
  837. }
  838. }
  839. } else {
  840. if ($user_id != api_get_user_id()) {
  841. if ($current_user_info['user_is_online_in_chat'] == 1) {
  842. $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name));
  843. $options = array('onclick' => "javascript:chatNotYetWith('".$message."')");
  844. $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'));
  845. $html .= Display::tag('li',
  846. Display::url(
  847. $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
  848. 'javascript:void(0);',
  849. $options
  850. )
  851. );
  852. }
  853. }
  854. }
  855. }*/
  856. $html .= '</ul></div></div>';
  857. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  858. $personal_course_list = UserManager::get_personal_session_course_list($user_id);
  859. $course_list_code = array();
  860. $i = 1;
  861. if (is_array($personal_course_list)) {
  862. foreach ($personal_course_list as $my_course) {
  863. if ($i <= 10) {
  864. $course_list_code[] = array('code' => $my_course['code']);
  865. } else {
  866. break;
  867. }
  868. $i++;
  869. }
  870. // To avoid repeated courses
  871. $course_list_code = array_unique_dimensional($course_list_code);
  872. }
  873. // Announcements
  874. $my_announcement_by_user_id = intval($user_id);
  875. $announcements = array();
  876. foreach ($course_list_code as $course) {
  877. $course_info = api_get_course_info($course['code']);
  878. if (!empty($course_info)) {
  879. $content = AnnouncementManager::get_all_annoucement_by_user_course(
  880. $course_info['code'],
  881. $my_announcement_by_user_id
  882. );
  883. if (!empty($content)) {
  884. $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']);
  885. $announcements[] = Display::tag('li', $url);
  886. }
  887. }
  888. }
  889. if (!empty($announcements)) {
  890. $html .= '<div class="social_menu_items">';
  891. $html .= '<ul>';
  892. foreach ($announcements as $announcement) {
  893. $html .= $announcement;
  894. }
  895. $html .= '</ul>';
  896. $html .= '</div>';
  897. }
  898. }
  899. }
  900. if ($show_delete_account_button) {
  901. $html .= '<div class="sidebar-nav"><ul><li>';
  902. $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php';
  903. $html .= Display::url(
  904. Display::return_icon(
  905. 'delete.png',
  906. get_lang('Unsubscribe'),
  907. array(),
  908. ICON_SIZE_TINY
  909. ).get_lang('Unsubscribe'),
  910. $url
  911. );
  912. $html .= '</li></ul></div>';
  913. }
  914. $html .= '';
  915. return $html;
  916. }
  917. /**
  918. * Displays a sortable table with the list of online users.
  919. * @param array $user_list The list of users to be shown
  920. * @param bool $wrap Whether we want the function to wrap the spans list in a div or not
  921. * @return string HTML block or null if and ID was defined
  922. * @assert (null) === false
  923. */
  924. public static function display_user_list($user_list, $wrap = true)
  925. {
  926. $html = null;
  927. if (isset($_GET['id']) or count($user_list) < 1) {
  928. return false;
  929. }
  930. $column_size = '12';
  931. $add_row = false;
  932. if (api_is_anonymous()) {
  933. $add_row = true;
  934. }
  935. $extra_params = array();
  936. $course_url = '';
  937. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  938. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  939. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  940. }
  941. $html .= '<div class="row">';
  942. foreach ($user_list as $uid) {
  943. $user_info = api_get_user_info($uid, $checkIfUserOnline = true);
  944. $lastname = $user_info['lastname'];
  945. $firstname = $user_info['firstname'];
  946. $completeName = $firstname.', '.$lastname;
  947. $user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png',get_lang('Teacher'),null,ICON_SIZE_TINY) : Display::return_icon('user.png',get_lang('Student'),null,ICON_SIZE_TINY);
  948. $status_icon_chat = null;
  949. if ($user_info['user_is_online_in_chat'] == 1) {
  950. $status_icon_chat = Display::return_icon('online.png', get_lang('Online'));
  951. } else {
  952. $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline'));
  953. }
  954. $userPicture = $user_info['avatar'];
  955. $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">';
  956. $url = null;
  957. // Anonymous users can't have access to the profile
  958. if (!api_is_anonymous()) {
  959. if (api_get_setting('allow_social_tool') == 'true') {
  960. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url;
  961. } else {
  962. $url = '?id='.$uid.$course_url;
  963. }
  964. } else {
  965. $url = null;
  966. }
  967. $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>';
  968. $html .= '<div class="col-xs-6 col-md-2">
  969. <div class="items-user">
  970. <div class="items-user-avatar">'.$img.'</div>
  971. <div class="items-user-name">
  972. '.$name.'
  973. </div>
  974. <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div>
  975. </div>
  976. </div>';
  977. }
  978. $counter = $_SESSION['who_is_online_counter'];
  979. if ($wrap) {
  980. $html .= '</div>';
  981. }
  982. if (count($user_list) >= 9) {
  983. $html .= '<div class="col-md-'.$column_size.'">
  984. <a class="btn btn-large btn-default" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
  985. }
  986. if ($wrap && $add_row) {
  987. $html .= '</div>';
  988. }
  989. return $html;
  990. }
  991. /**
  992. * Displays the information of an individual user
  993. * @param int $user_id
  994. */
  995. public static function display_individual_user($user_id)
  996. {
  997. global $interbreadcrumb;
  998. $safe_user_id = intval($user_id);
  999. $currentUserId = api_get_user_id();
  1000. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  1001. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  1002. $result = Database::query($sql);
  1003. $html = null;
  1004. if (Database::num_rows($result) == 1) {
  1005. $user_object = Database::fetch_object($result);
  1006. $userInfo = api_get_user_info($user_id);
  1007. $alt = $userInfo['complete_name'].($currentUserId == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  1008. $status = get_status_from_code($user_object->status);
  1009. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  1010. $html .= '<div class ="thumbnail">';
  1011. $fullurl = $userInfo['avatar'];
  1012. $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
  1013. if (!empty($status)) {
  1014. $html .= '<div class="caption">'.$status.'</div>';
  1015. }
  1016. $html .= '</div>';
  1017. if (api_get_setting('show_email_addresses') == 'true') {
  1018. $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
  1019. }
  1020. if ($user_object->competences) {
  1021. $html .= Display::page_subheader(get_lang('MyCompetences'));
  1022. $html .= '<p>'.$user_object->competences.'</p>';
  1023. }
  1024. if ($user_object->diplomas) {
  1025. $html .= Display::page_subheader(get_lang('MyDiplomas'));
  1026. $html .= '<p>'.$user_object->diplomas.'</p>';
  1027. }
  1028. if ($user_object->teach) {
  1029. $html .= Display::page_subheader(get_lang('MyTeach'));
  1030. $html .= '<p>'.$user_object->teach.'</p>';
  1031. }
  1032. SocialManager::display_productions($user_object->user_id);
  1033. if ($user_object->openarea) {
  1034. $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
  1035. $html .= '<p>'.$user_object->openarea.'</p>';
  1036. }
  1037. } else {
  1038. $html .= '<div class="actions-title">';
  1039. $html .= get_lang('UsersOnLineList');
  1040. $html .= '</div>';
  1041. }
  1042. return $html;
  1043. }
  1044. /**
  1045. * Display productions in who is online
  1046. * @param int $user_id User id
  1047. */
  1048. public static function display_productions($user_id)
  1049. {
  1050. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
  1051. $sysdir = UserManager::getUserPathById($user_id, 'system');
  1052. $webdir = UserManager::getUserPathById($user_id, 'web');
  1053. if (!is_dir($sysdir)) {
  1054. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  1055. }
  1056. $productions = UserManager::get_user_productions($user_id);
  1057. if (count($productions) > 0) {
  1058. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  1059. echo '<dd><ul>';
  1060. foreach ($productions as $file) {
  1061. // Only display direct file links to avoid browsing an empty directory
  1062. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  1063. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  1064. }
  1065. // Real productions are under a subdirectory by the User's id
  1066. if (is_dir($sysdir.$file)) {
  1067. $subs = scandir($sysdir.$file);
  1068. foreach ($subs as $my => $sub) {
  1069. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  1070. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  1071. }
  1072. }
  1073. }
  1074. }
  1075. echo '</ul></dd>';
  1076. }
  1077. }
  1078. /**
  1079. * @param string $content
  1080. * @param string $span_count
  1081. * @return string
  1082. */
  1083. public static function social_wrapper_div($content, $span_count)
  1084. {
  1085. $span_count = intval($span_count);
  1086. $html = '<div class="span'.$span_count.'">';
  1087. $html .= '<div class="well_border">';
  1088. $html .= $content;
  1089. $html .= '</div></div>';
  1090. return $html;
  1091. }
  1092. /**
  1093. * Dummy function
  1094. *
  1095. */
  1096. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
  1097. {
  1098. $content = '';
  1099. switch ($place) {
  1100. case SOCIAL_CENTER_PLUGIN:
  1101. $social_plugins = array(1, 2);
  1102. if (is_array($social_plugins) && count($social_plugins) > 0) {
  1103. $content.= '<div id="social-plugins">';
  1104. foreach ($social_plugins as $plugin) {
  1105. $content.= '<div class="social-plugin-item">';
  1106. $content.= $plugin;
  1107. $content.= '</div>';
  1108. }
  1109. $content.= '</div>';
  1110. }
  1111. break;
  1112. case SOCIAL_LEFT_PLUGIN:
  1113. break;
  1114. case SOCIAL_RIGHT_PLUGIN:
  1115. break;
  1116. }
  1117. return $content;
  1118. }
  1119. /**
  1120. * Sends a message to someone's wall
  1121. * @param int $userId id of author
  1122. * @param int $friendId id where we send the message
  1123. * @param string $messageContent of the message
  1124. * @param int $messageId id parent
  1125. * @param string $messageStatus status type of message
  1126. * @return boolean
  1127. * @author Yannick Warnier
  1128. */
  1129. public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0 ,$messageStatus)
  1130. {
  1131. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1132. $userId = intval($userId);
  1133. $friendId = intval($friendId);
  1134. $messageId = intval($messageId);
  1135. //Just in case we replace the and \n and \n\r while saving in the DB
  1136. $messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
  1137. $attributes = array(
  1138. 'user_sender_id' => $userId,
  1139. 'user_receiver_id' => $friendId,
  1140. 'msg_status' => $messageStatus,
  1141. 'send_date' => api_get_utc_datetime(),
  1142. 'title' => '',
  1143. 'content' => $messageContent,
  1144. 'parent_id' => $messageId
  1145. );
  1146. return Database::insert($tblMessage, $attributes);
  1147. }
  1148. /**
  1149. * Send File attachment (jpg,png)
  1150. * @author Anibal Copitan
  1151. * @param int $userId id user
  1152. * @param array $fileAttach
  1153. * @param int $messageId id message (relation with main message)
  1154. * @param string $fileComment description attachment file
  1155. * @return bool
  1156. */
  1157. public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
  1158. {
  1159. $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1160. // create directory
  1161. $social = '/social/';
  1162. $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social;
  1163. $safeFileComment = Database::escape_string($fileComment);
  1164. $safeFileName = Database::escape_string($fileAttach['name']);
  1165. $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
  1166. $allowedTypes = api_get_supported_image_extensions();
  1167. if (!in_array($extension, $allowedTypes)) {
  1168. $flag = false;
  1169. } else {
  1170. $newFileName = uniqid('') . '.' . $extension;
  1171. if (!file_exists($pathMessageAttach)) {
  1172. @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
  1173. }
  1174. $newPath = $pathMessageAttach . $newFileName;
  1175. if (is_uploaded_file($fileAttach['tmp_name'])) {
  1176. @copy($fileAttach['tmp_name'], $newPath);
  1177. }
  1178. $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
  1179. $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
  1180. $big = new Image($newPath);
  1181. $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) &&
  1182. $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) &&
  1183. $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
  1184. // Insert
  1185. $newFileName = $social.$newFileName;
  1186. $params = [
  1187. 'filename' => $safeFileName,
  1188. 'comment' => $safeFileComment,
  1189. 'path' => $newFileName,
  1190. 'message_id' => $messageId,
  1191. 'size' => $fileAttach['size'],
  1192. ];
  1193. Database::insert($tbl_message_attach, $params);
  1194. $flag = true;
  1195. }
  1196. return $flag;
  1197. }
  1198. /**
  1199. * Gets all messages from someone's wall (within specific limits)
  1200. * @param int $userId id of wall shown
  1201. * @param string $messageStatus status wall message
  1202. * @param int|string $parentId id message (Post main)
  1203. * @param date $start Date from which we want to show the messages, in UTC time
  1204. * @param int $limit Limit for the number of parent messages we want to show
  1205. * @param int $offset Wall message query offset
  1206. * @return boolean
  1207. * @author Yannick Warnier
  1208. */
  1209. public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0)
  1210. {
  1211. if (empty($start)) {
  1212. $start = '0000-00-00';
  1213. }
  1214. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1215. $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1216. $userId = intval($userId);
  1217. $start = Database::escape_string($start);
  1218. $limit = intval($limit);
  1219. $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id,
  1220. (SELECT ma.path FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as path,
  1221. (SELECT ma.filename FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as filename
  1222. FROM $tblMessage tm
  1223. WHERE user_receiver_id = $userId
  1224. AND send_date > '$start' ";
  1225. $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' ";
  1226. $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' ";
  1227. $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit ";
  1228. $messages = array();
  1229. $res = Database::query($sql);
  1230. if (Database::num_rows($res) > 0) {
  1231. while ($row = Database::fetch_array($res)) {
  1232. $messages[] = $row;
  1233. }
  1234. }
  1235. return $messages;
  1236. }
  1237. /**
  1238. * Gets all messages from someone's wall (within specific limits), formatted
  1239. * @param int $userId USER ID of the person's wall
  1240. * @param int $friendId id person
  1241. * @param int $idMessage id message
  1242. * @param string $start Start date (from when we want the messages until today)
  1243. * @param int $limit Limit to the number of messages we want
  1244. * @param int $offset Wall messages offset
  1245. * @return string HTML formatted string to show messages
  1246. */
  1247. public static function getWallMessagesHTML($userId, $friendId, $idMessage, $start = null, $limit = 10, $offset = 0)
  1248. {
  1249. if (empty($start)) {
  1250. $start = '0000-00-00';
  1251. }
  1252. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1253. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL, $idMessage, $start, $limit, $offset);
  1254. $formattedList = '<div class="sub-mediapost">';
  1255. $users = array();
  1256. // The messages are ordered by date descendant, for comments we need ascendant
  1257. krsort($messages);
  1258. foreach ($messages as $message) {
  1259. $date = api_get_local_time($message['send_date']);
  1260. $userIdLoop = $message['user_sender_id'];
  1261. if (!isset($users[$userIdLoop])) {
  1262. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1263. }
  1264. $nameComplete = api_is_western_name_order()
  1265. ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname']
  1266. : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname'];
  1267. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
  1268. $media = '';
  1269. $media .= '<div class="rep-post">';
  1270. if ($isOwnWall) {
  1271. $media .= '<div class="pull-right deleted-mgs">';
  1272. $media .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1273. $message['id'].'">x</a>';
  1274. $media .= '</div>';
  1275. }
  1276. $media .= '<div class="user-image">';
  1277. $media .= '<a href="'.$url.'" ><img src="'. $users[$userIdLoop]['avatar'] .
  1278. '" alt="'.$users[$userIdLoop]['complete_name'].'" class="avatar-thumb"></a>';
  1279. $media .= '</div>';
  1280. $media .= '<div class="user-data">';
  1281. $media .= '<div class="username">' . '<a href="'.$url.'">'.$nameComplete.'</a></div>';
  1282. $media .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1283. $media .= '</div>';
  1284. $media .= '<div class="msg-content">';
  1285. $media .= '<p>'.Security::remove_XSS($message['content']).'</p>';
  1286. $media .= '</div></div>';
  1287. $formattedList .= $media;
  1288. }
  1289. $formattedList .= '</div>';
  1290. $formattedList .= '<div class="mediapost-form">';
  1291. $formattedList .= '<form name="social_wall_message" method="POST">
  1292. <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label>
  1293. <input type="hidden" name = "messageId" value="'.$idMessage.'" />
  1294. <textarea placeholder="'.get_lang('SocialWriteNewComment').
  1295. '" name="social_wall_new_msg" rows="1" style="width:80%;" ></textarea>
  1296. <button type="submit" name="social_wall_new_msg_submit"
  1297. class="pull-right btn btn-default" /><i class="fa fa-pencil"></i> '.get_lang('Post').'</button>
  1298. </form>';
  1299. $formattedList .= '</div>';
  1300. return $formattedList;
  1301. }
  1302. /**
  1303. * Gets all user's starting wall messages (within specific limits)
  1304. * @param int $userId User's id
  1305. * @param int $friendId Friend's id
  1306. * @param date $start Start date (from when we want the messages until today)
  1307. * @param int $limit Limit to the number of messages we want
  1308. * @param int $offset Wall messages offset
  1309. * @return array $data return user's starting wall messages along with message extra data
  1310. */
  1311. public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0)
  1312. {
  1313. if (empty($start)) {
  1314. $start = '0000-00-00';
  1315. }
  1316. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1317. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST , null, $start, $limit, $offset);
  1318. $users = array();
  1319. $data = array();
  1320. foreach ($messages as $key => $message) {
  1321. $userIdLoop = $message['user_sender_id'];
  1322. $userFriendIdLoop = $message['user_receiver_id'];
  1323. if (!isset($users[$userIdLoop])) {
  1324. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1325. }
  1326. if (!isset($users[$userFriendIdLoop])) {
  1327. $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop);
  1328. }
  1329. $html = '';
  1330. $html .= self::headerMessagePost(
  1331. $message['user_sender_id'],
  1332. $message['user_receiver_id'],
  1333. $users,
  1334. $message,
  1335. $isOwnWall
  1336. );
  1337. $data[$key]['id'] = $message['id'];
  1338. $data[$key]['html'] = $html;
  1339. }
  1340. return $data;
  1341. }
  1342. /**
  1343. * Returns the formatted header message post
  1344. * @param int $authorId Author's id
  1345. * @param int $receiverId Receiver's id
  1346. * @param array $users Author's and receiver's data
  1347. * @param array $message Message data
  1348. * @param boolean $isOwnWall Determines if the author is in its own social wall or not
  1349. * @return string $html The formatted header message post
  1350. */
  1351. private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false)
  1352. {
  1353. $date = api_get_local_time($message['send_date']);
  1354. $avatarAuthor = $users[$authorId]['avatar'];
  1355. $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
  1356. $nameCompleteAuthor = api_get_person_name(
  1357. $users[$authorId]['firstname'],
  1358. $users[$authorId]['lastname']
  1359. );
  1360. $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
  1361. $nameCompleteReceiver = api_get_person_name(
  1362. $users[$receiverId]['firstname'],
  1363. $users[$receiverId]['lastname']
  1364. );
  1365. $htmlReceiver = '';
  1366. if ($authorId != $receiverId) {
  1367. $htmlReceiver = ' > <a href="'.$urlReceiver.'">' . $nameCompleteReceiver . '</a> ';
  1368. }
  1369. $wallImage = '';
  1370. if (!empty($message['path'])) {
  1371. $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG);
  1372. $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL);
  1373. $wallImage = '<a class="thumbnail ajax" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>';
  1374. }
  1375. $htmlDelete = '';
  1376. if ($isOwnWall) {
  1377. $htmlDelete .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1378. $message['id'].'">x</a>';
  1379. }
  1380. $html = '';
  1381. $html .= '<div class="top-mediapost" >';
  1382. if ($isOwnWall) {
  1383. $html .= '<div class="pull-right deleted-mgs">';
  1384. $html .= $htmlDelete;
  1385. $html .= '</div>';
  1386. }
  1387. $html .= '<div class="user-image" >';
  1388. $html .= '<a href="'.$urlAuthor.'">'.'<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>';
  1389. $html .= '</div>';
  1390. $html .= '<div class="user-data">';
  1391. $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>';
  1392. $html .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1393. $html .= '</div>';
  1394. $html .= '<div class="msg-content">';
  1395. $html .= '<div class="img-post">';
  1396. $html .= $wallImage;
  1397. $html .= '</div>';
  1398. $html .= '<p>'. Security::remove_XSS($message['content']).'</p>';
  1399. $html .= '</div>';
  1400. $html .= '</div>'; // end mediaPost
  1401. return $html;
  1402. }
  1403. /**
  1404. * Get schedule html (with data openGrap)
  1405. * @param string $text Content text
  1406. * @return string $newText Content text with OpenGraph
  1407. */
  1408. public static function readContentWithOpenGraph($text)
  1409. {
  1410. // search link in first line
  1411. $regExUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  1412. $newText = '';
  1413. if (preg_match($regExUrl, $text, $url)) {
  1414. // make the urls hyper links
  1415. $newText .= preg_replace($regExUrl, "<a target=\"_blank\" href=" . $url[0] . ">".$url[0]."</a> ", $text);
  1416. // Comment this line to disable OpenGraph
  1417. $newText .= self::getHtmlByLink($url[0]);
  1418. } else {
  1419. $newText .= $text;
  1420. }
  1421. return $newText;
  1422. }
  1423. /**
  1424. * html with data OpenGrap
  1425. * @param $link url
  1426. * @return string data html
  1427. */
  1428. public static function getHtmlByLink($link)
  1429. {
  1430. $graph = OpenGraph::fetch($link);
  1431. $url = $graph->url;
  1432. $image = $graph->image;
  1433. $domain = empty($url) ? parse_url($link) : parse_url($url);
  1434. $domain = $domain['scheme'].'://'.$domain['host'];
  1435. // Trick to verify if the Image Url Exist because of some bad metatag dev
  1436. if (self::verifyUrl($image) == false){
  1437. if (!($image[0] == '/')){
  1438. $domain = $domain . '/';
  1439. }
  1440. $image = $domain . $image;
  1441. }
  1442. $title = $graph->title;
  1443. $html = '<div class="thumbnail">';
  1444. $html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>';
  1445. $html .= empty($image) ? '' : '<img alt="" src="'.$image.'" height="160" ></a>';
  1446. $html .= empty($graph->description) ? '' : '<div>'.$graph->description.'</div>';
  1447. $html .= "</div>";
  1448. return $html;
  1449. }
  1450. /**
  1451. * verify if Url Exist - Using Curl
  1452. * @param $uri url
  1453. *
  1454. * @return boolean
  1455. */
  1456. public static function verifyUrl($uri)
  1457. {
  1458. $curl = curl_init($uri);
  1459. curl_setopt($curl, CURLOPT_FAILONERROR, true);
  1460. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  1461. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1462. curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  1463. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  1464. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1465. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  1466. $response = curl_exec($curl);
  1467. curl_close($curl);
  1468. if (!empty($response)) {
  1469. return true;
  1470. } else {
  1471. return false;
  1472. }
  1473. }
  1474. /**
  1475. * Get full image path from a path and a size
  1476. * @param string $path
  1477. * @return string
  1478. */
  1479. private static function getImagePath($path, $size = '')
  1480. {
  1481. $name = '';
  1482. $array = preg_split('#\/#', $path);
  1483. if (isset($array[2]) && !empty($array[2])) {
  1484. if ($size == IMAGE_WALL_SMALL) {
  1485. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1486. }else if($size == IMAGE_WALL_MEDIUM){
  1487. $name = IMAGE_WALL_MEDIUM. '_' . $array[2];
  1488. }else if($size == IMAGE_WALL_BIG){
  1489. $name = IMAGE_WALL_BIG. '_' . $array[2];
  1490. }else {
  1491. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1492. }
  1493. $lessImage = str_replace($array[2], '', $path);
  1494. $name = $lessImage . $name;
  1495. }
  1496. return $name;
  1497. }
  1498. /**
  1499. * Delete messages delete logic
  1500. * @param int $id id message to delete.
  1501. * @return bool status query
  1502. */
  1503. public static function deleteMessage($id)
  1504. {
  1505. $id = intval($id);
  1506. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1507. $statusMessage = MESSAGE_STATUS_WALL_DELETE;
  1508. $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
  1509. return Database::query($sql);
  1510. }
  1511. /**
  1512. * Generate the social block for a user
  1513. * @param Template $template
  1514. * @param int $userId The user id
  1515. * @param string $groupBlock Optional. Highlight link possible values:
  1516. * group_add, home, messages, messages_inbox, messages_compose,
  1517. * messages_outbox, invitations, shared_profile, friends, groups, search
  1518. * @param int $groupId Optional. Group ID
  1519. * @return string The HTML code with the social block
  1520. */
  1521. public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0)
  1522. {
  1523. if (api_get_setting('allow_social_tool') != 'true') {
  1524. return '';
  1525. }
  1526. $socialAvatarBlock = SocialManager::show_social_avatar_block(
  1527. $groupBlock,
  1528. $groupId,
  1529. $userId
  1530. );
  1531. $profileEditionLink = null;
  1532. if (api_get_user_id() == $userId) {
  1533. $profileEditionLink = Display::getProfileEditionLink($userId);
  1534. }
  1535. $vCardUserLink = Display::getVCardUserLink($userId);
  1536. $userInfo = api_get_user_info($userId, true, false, true);
  1537. $template->assign('user', $userInfo);
  1538. $template->assign('social_avatar_block', $socialAvatarBlock);
  1539. $template->assign('profile_edition_link', $profileEditionLink);
  1540. //Added the link to export the vCard to the Template
  1541. $template->assign('vcard_user_link', $vCardUserLink);
  1542. if (api_get_setting('gamification_mode') === '1') {
  1543. $gamificationPoints = GamificationUtils::getTotalUserPoints(
  1544. $userId,
  1545. $userInfo['status']
  1546. );
  1547. $template->assign('gamification_points', $gamificationPoints);
  1548. }
  1549. $chatEnabled = api_is_global_chat_enabled();
  1550. $template->assign('chat_enabled', $chatEnabled);
  1551. $templateName = $template->get_template('social/user_block.tpl');
  1552. if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
  1553. $templateName = $template->get_template('social/group_block.tpl');
  1554. }
  1555. $template->assign('social_avatar_block', $template->fetch($templateName));
  1556. }
  1557. /**
  1558. * @param int $user_id
  1559. * @param $link_shared
  1560. * @param $show_full_profile
  1561. * @return string
  1562. */
  1563. public static function listMyFriends($user_id, $link_shared, $show_full_profile)
  1564. {
  1565. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1566. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1567. $number_of_images = 30;
  1568. $number_friends = count($friends);
  1569. $friendHtml = '';
  1570. if ($number_friends != 0) {
  1571. if ($number_friends > $number_of_images) {
  1572. if (api_get_user_id() == $user_id) {
  1573. $friendHtml.= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
  1574. } else {
  1575. $friendHtml.= ' <span>'
  1576. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  1577. .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
  1578. .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
  1579. }
  1580. }
  1581. $friendHtml.= '<ul class="nav nav-list">';
  1582. $j = 1;
  1583. for ($k=0; $k < $number_friends; $k++) {
  1584. if ($j > $number_of_images) break;
  1585. if (isset($friends[$k])) {
  1586. $friend = $friends[$k];
  1587. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1588. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1589. if ($user_info_friend['user_is_online']) {
  1590. $statusIcon = Display::span('', array('class' => 'online_user_in_text'));
  1591. } else {
  1592. $statusIcon = Display::span('', array('class' => 'offline_user_in_text'));
  1593. }
  1594. $friendHtml.= '<li class="">';
  1595. $friendHtml.= '<div>';
  1596. // the height = 92 must be the same in the image_friend_network span style in default.css
  1597. $friends_profile = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1598. $friendHtml.= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
  1599. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1600. $friendHtml.= $statusIcon .'<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">' . $name_user .'</a>';
  1601. $friendHtml.= '</div>';
  1602. $friendHtml.= '</li>';
  1603. }
  1604. $j++;
  1605. }
  1606. $friendHtml.='</ul>';
  1607. } else {
  1608. $friendHtml.= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />'
  1609. .'<a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"><i class="fa fa-search"></i> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1610. }
  1611. $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' (' . $number_friends . ')' );
  1612. return $friendHtml;
  1613. }
  1614. /**
  1615. * @param int $user_id
  1616. * @param $link_shared
  1617. * @param $show_full_profile
  1618. * @return string
  1619. */
  1620. public static function listMyFriendsBlock($user_id, $link_shared, $show_full_profile)
  1621. {
  1622. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1623. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1624. $number_of_images = 30;
  1625. $number_friends = count($friends);
  1626. $friendHtml = '';
  1627. if ($number_friends != 0) {
  1628. $friendHtml.= '<ul class="list-group">';
  1629. $j = 1;
  1630. for ($k=0; $k < $number_friends; $k++) {
  1631. if ($j > $number_of_images) break;
  1632. if (isset($friends[$k])) {
  1633. $friend = $friends[$k];
  1634. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1635. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1636. if ($user_info_friend['user_is_online']) {
  1637. $statusIcon = Display::return_icon('statusonline.png',get_lang('Online'));
  1638. $status=1;
  1639. } else {
  1640. $statusIcon = Display::return_icon('statusoffline.png',get_lang('Offline'));
  1641. $status=0;
  1642. }
  1643. $friendHtml.= '<li class="list-group-item">';
  1644. $friendAvatarMedium = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_MEDIUM);
  1645. $friendAvatarSmall = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1646. $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
  1647. $showLinkToChat = api_is_global_chat_enabled() &&
  1648. $friend['friend_user_id'] != api_get_user_id();
  1649. if ($showLinkToChat){
  1650. $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);">';
  1651. $friendHtml .= $friend_avatar.' <span class="username">' . $name_user . '</span>';
  1652. $friendHtml .= '<span class="status">' . $statusIcon . '</span>';
  1653. } else {
  1654. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1655. $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">';
  1656. $friendHtml .= $friend_avatar.' <span class="username-all">' . $name_user . '</span>';
  1657. }
  1658. $friendHtml .= '</a>';
  1659. $friendHtml.= '</li>';
  1660. }
  1661. $j++;
  1662. }
  1663. $friendHtml.='</ul>';
  1664. } else {
  1665. $friendHtml.= '<div class="help">'.get_lang('NoFriendsInYourContactList').' '
  1666. .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><i class="fa fa-search"></i> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1667. }
  1668. return $friendHtml;
  1669. }
  1670. /**
  1671. * @return string
  1672. */
  1673. public static function getWallForm()
  1674. {
  1675. $form = new FormValidator(
  1676. 'social_wall_main',
  1677. 'post',
  1678. api_get_path(WEB_CODE_PATH).'social/profile.php',
  1679. null,
  1680. array('enctype' => 'multipart/form-data')
  1681. );
  1682. $form->addTextarea(
  1683. 'social_wall_new_msg_main',
  1684. null,
  1685. [
  1686. 'placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'),
  1687. 'style' => 'width : 100%'
  1688. ]
  1689. );
  1690. $form->addHtml('<div class="form-group "><div class="url_preview col-md-9 panel-body"></div></div>');
  1691. $form->addHidden('url_content', '');
  1692. $form->addButtonSend(get_lang('Post'));
  1693. $html = Display::panel($form->returnForm(), get_lang('SocialWall'));
  1694. return $html;
  1695. }
  1696. /**
  1697. * @param int $userId
  1698. * @param int $friendId
  1699. * @return string
  1700. */
  1701. public static function getWallMessagesByUser($userId, $friendId)
  1702. {
  1703. $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId);
  1704. $html = '';
  1705. foreach ($messages as $message) {
  1706. $post = $message['html'];
  1707. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']);
  1708. $html .= $post.$comment;
  1709. }
  1710. return $html;
  1711. }
  1712. /**
  1713. * Get HTML code block for user skills
  1714. * @param int $userId The user ID
  1715. * @return string
  1716. */
  1717. public static function getSkillBlock($userId)
  1718. {
  1719. if (api_get_setting('allow_skills_tool') !== 'true') {
  1720. return null;
  1721. }
  1722. $skill = new Skill();
  1723. $ranking = $skill->get_user_skill_ranking($userId);
  1724. $skills = $skill->get_user_skills($userId, true);
  1725. $template = new Template(null, false, false, false, false, false);
  1726. $template->assign('ranking', $ranking);
  1727. $template->assign('skills', $skills);
  1728. $template->assign(
  1729. 'show_skills_report_link',
  1730. api_is_student() || api_is_student_boss() || api_is_drh()
  1731. );
  1732. $skillBlock = $template->get_template('social/skills_block.tpl');
  1733. return $template->fetch($skillBlock);
  1734. }
  1735. }