social.lib.php 76 KB

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