group_portal_manager.lib.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This library provides functions for the group management.
  5. * Include/require it in your code to use its functionality.
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. * @package chamilo.library
  8. */
  9. /**
  10. * Code
  11. */
  12. // Group permissions
  13. define('GROUP_PERMISSION_OPEN' , '1');
  14. define('GROUP_PERMISSION_CLOSED', '2');
  15. // Group user permissions
  16. define('GROUP_USER_PERMISSION_ADMIN' , '1'); // the admin of a group
  17. define('GROUP_USER_PERMISSION_READER', '2'); // a normal user
  18. define('GROUP_USER_PERMISSION_PENDING_INVITATION', '3'); // When an admin/moderator invites a user
  19. define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', '4'); // an user joins a group
  20. define('GROUP_USER_PERMISSION_MODERATOR', '5'); // a moderator
  21. define('GROUP_USER_PERMISSION_ANONYMOUS' , '6'); // an anonymous user
  22. define('GROUP_USER_PERMISSION_HRM', '7'); // a human resources manager
  23. define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
  24. define('GROUP_IMAGE_SIZE_BIG', 2);
  25. define('GROUP_IMAGE_SIZE_MEDIUM', 3);
  26. define('GROUP_IMAGE_SIZE_SMALL', 4);
  27. define('GROUP_TITLE_LENGTH', 50);
  28. /**
  29. * Class
  30. * @package chamilo.library
  31. */
  32. class GroupPortalManager {
  33. /**
  34. * Creates a new group
  35. *
  36. * @author Julio Montoya <gugli100@gmail.com>,
  37. *
  38. * @param string The URL of the site
  39. * @param string The description of the site
  40. * @param int is active or not
  41. * @param int the user_id of the owner
  42. * @return boolean if success
  43. */
  44. public static function add($name, $description, $url, $visibility, $picture='') {
  45. $now = api_get_utc_datetime();
  46. $table = Database :: get_main_table(TABLE_MAIN_GROUP);
  47. $sql = "INSERT INTO $table
  48. SET name = '".Database::escape_string($name)."',
  49. description = '".Database::escape_string($description)."',
  50. picture_uri = '".Database::escape_string($picture)."',
  51. url = '".Database::escape_string($url)."',
  52. visibility = '".Database::escape_string($visibility)."',
  53. created_on = '".$now."',
  54. updated_on = '".$now."'";
  55. Database::query($sql);
  56. $return = Database::insert_id();
  57. return $return;
  58. }
  59. /**
  60. * Updates a group
  61. * @author Julio Montoya <gugli100@gmail.com>,
  62. *
  63. * @param int The id
  64. * @param string The description of the site
  65. * @param int is active or not
  66. * @param int the user_id of the owner
  67. * @return boolean if success
  68. */
  69. public static function update($group_id, $name, $description, $url, $visibility, $picture_uri) {
  70. $group_id = intval($group_id);
  71. $table = Database::get_main_table(TABLE_MAIN_GROUP);
  72. $now = api_get_utc_datetime();
  73. $sql = "UPDATE $table
  74. SET name = '".Database::escape_string($name)."',
  75. description = '".Database::escape_string($description)."',
  76. picture_uri = '".Database::escape_string($picture_uri)."',
  77. url = '".Database::escape_string($url)."',
  78. visibility = '".Database::escape_string($visibility)."',
  79. updated_on = '".$now."'
  80. WHERE id = '$group_id'";
  81. $result = Database::query($sql);
  82. return $result;
  83. }
  84. /**
  85. * Deletes a group
  86. * @author Julio Montoya
  87. * @param int id
  88. * @return boolean true if success
  89. * */
  90. public static function delete($id)
  91. {
  92. $id = intval($id);
  93. $table = Database :: get_main_table(TABLE_MAIN_GROUP);
  94. $sql= "DELETE FROM $table WHERE id = ".Database::escape_string($id);
  95. $result = Database::query($sql);
  96. //deleting all relationship with users and groups
  97. self::delete_users($id);
  98. // delete group image
  99. self::delete_group_picture($id);
  100. return $result;
  101. }
  102. /**
  103. * Gets data of all groups
  104. * @author Julio Montoya
  105. * @param int visibility
  106. * @param int from which record the results will begin (use for pagination)
  107. * @param int number of items
  108. * @return array
  109. * */
  110. public static function get_all_group_data($visibility = GROUP_PERMISSION_OPEN, $from=0, $number_of_items=10)
  111. {
  112. $table = Database :: get_main_table(TABLE_MAIN_GROUP);
  113. $visibility = intval($visibility);
  114. $sql = "SELECT name, description, picture_uri FROM $table WHERE visibility = $visibility ";
  115. $res = Database::query($sql);
  116. $data = array ();
  117. while ($item = Database::fetch_array($res)) {
  118. $data[] = $item;
  119. }
  120. return $data;
  121. }
  122. /**
  123. * Gets a list of all group
  124. * @param id of a group not to include (i.e. to exclude)
  125. * @return array : id => name
  126. **/
  127. public static function get_groups_list($without_this_one = NULL ) {
  128. $where='';
  129. if ( isset($without_this_one) && (intval($without_this_one) == $without_this_one) ) {
  130. $where = "WHERE id <> $without_this_one";
  131. }
  132. $table = Database :: get_main_table(TABLE_MAIN_GROUP);
  133. $sql = "SELECT id, name FROM $table $where order by name";
  134. $res = Database::query($sql);
  135. $list = array ();
  136. while ($item = Database::fetch_assoc($res)) {
  137. $list[$item['id']] = $item['name'];
  138. }
  139. return $list;
  140. }
  141. /**
  142. * Gets the group data
  143. *
  144. *
  145. */
  146. public static function get_group_data($group_id)
  147. {
  148. $table = Database :: get_main_table(TABLE_MAIN_GROUP);
  149. $group_id = intval($group_id);
  150. $sql = "SELECT id, name, description, picture_uri, url, visibility FROM $table WHERE id = $group_id ";
  151. $res = Database::query($sql);
  152. $item = array();
  153. if (Database::num_rows($res)>0) {
  154. $item = Database::fetch_array($res,'ASSOC');
  155. }
  156. return $item;
  157. }
  158. /**
  159. * Set a parent group
  160. * @param group_id
  161. * @param parent_group, if 0, we delete the parent_group association
  162. * @param relation_type
  163. * @return true or false
  164. **/
  165. public static function set_parent_group($group_id, $parent_group_id, $relation_type = 1){
  166. $table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
  167. $group_id = intval($group_id);
  168. $parent_group_id = intval($parent_group_id);
  169. if ($parent_group_id == 0) {
  170. $sql = "DELETE FROM $table WHERE subgroup_id = $group_id";
  171. } else {
  172. $sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
  173. $res = Database::query($sql);
  174. if (Database::num_rows($res)==0) {
  175. $sql = "INSERT INTO $table SET group_id = $parent_group_id, subgroup_id = $group_id, relation_type = $relation_type";
  176. } else {
  177. $sql = "UPDATE $table SET group_id = $parent_group_id, relation_type = $relation_type WHERE subgroup_id = $group_id";
  178. }
  179. }
  180. $res = Database::query($sql);
  181. return($res);
  182. }
  183. /**
  184. * Get the parent group
  185. * @param group_id
  186. * @param relation_type
  187. * @return int parent_group_id or false
  188. **/
  189. public static function get_parent_group($group_id, $relation_type=1) {
  190. $table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
  191. $group_id=intval($group_id);
  192. $parent_group_id=intval($parent_group_id);
  193. $sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
  194. $res = Database::query($sql);
  195. if (Database::num_rows($res)==0) {
  196. return 0;
  197. } else {
  198. $arr = Database::fetch_assoc($res);
  199. return $arr['group_id'];
  200. }
  201. }
  202. public static function get_subgroups($root, $level) {
  203. $t_group = Database::get_main_table(TABLE_MAIN_GROUP);
  204. $t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
  205. $select_part = "SELECT ";
  206. $cond_part='';
  207. for ($i=1; $i <= $level; $i++) {
  208. $g_number=$i;
  209. $rg_number=$i-1;
  210. if ( $i == $level) {
  211. $select_part .= "g$i.id as id_$i, g$i.name as name_$i ";
  212. } else {
  213. $select_part .="g$i.id as id_$i, g$i.name name_$i, ";
  214. }
  215. if ($i == 1) {
  216. $cond_part .= "FROM $t_group g1 JOIN $t_rel_group rg0 on g1.id = rg0.subgroup_id and rg0.group_id = $root ";
  217. } else {
  218. $cond_part .= "LEFT JOIN $t_rel_group rg$rg_number on g$rg_number.id = rg$rg_number.group_id ";
  219. $cond_part .= "LEFT JOIN $t_group g$g_number on rg$rg_number.subgroup_id = g$g_number.id ";
  220. }
  221. }
  222. $sql = $select_part.' '. $cond_part;
  223. $res = Database::query($sql);
  224. $toreturn = array();
  225. while ($item = Database::fetch_assoc($res)) {
  226. foreach ($item as $key => $value ){
  227. if ($key == 'id_1') {
  228. $toreturn[$value]['name'] = $item['name_1'];
  229. } else {
  230. $temp = explode('_',$key);
  231. $index_key = $temp[1];
  232. $string_key = $temp[0];
  233. $previous_key = $string_key.'_'.$index_key-1;
  234. if ( $string_key == 'id' && isset($item[$key]) ) {
  235. $toreturn[$item[$previous_key]]['hrms'][$index_key]['name'] = $item['name_'.$index_id];
  236. }
  237. }
  238. }
  239. }
  240. return $toreturn;
  241. }
  242. public static function get_parent_groups($group_id) {
  243. $t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
  244. $max_level = 10;
  245. $select_part = "SELECT ";
  246. $cond_part='';
  247. for ($i=1; $i <= $max_level; $i++) {
  248. $g_number=$i;
  249. $rg_number=$i-1;
  250. if ( $i == $max_level) {
  251. $select_part .= "rg$rg_number.group_id as id_$rg_number ";
  252. } else {
  253. $select_part .="rg$rg_number.group_id as id_$rg_number, ";
  254. }
  255. if ($i == 1) {
  256. $cond_part .= "FROM $t_rel_group rg0 LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id ";
  257. } else {
  258. $cond_part .= " LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id ";
  259. }
  260. }
  261. $sql = $select_part.' '. $cond_part . "WHERE rg0.subgroup_id='$group_id'";
  262. $res = Database::query($sql);
  263. $temp_arr = Database::fetch_array($res, 'NUM');
  264. $toreturn = array();
  265. if (is_array($temp_arr)) {
  266. foreach ($temp_arr as $elt) {
  267. if (isset($elt)) {
  268. $toreturn[] = $elt;
  269. }
  270. }
  271. }
  272. return $toreturn;
  273. }
  274. /**
  275. * Gets the tags from a given group
  276. * @param int group id
  277. * @param bool show group links or not
  278. *
  279. */
  280. public static function get_group_tags($group_id, $show_tag_links = true)
  281. {
  282. $tag = Database :: get_main_table(TABLE_MAIN_TAG);
  283. $table_group_rel_tag = Database :: get_main_table(TABLE_MAIN_GROUP_REL_TAG);
  284. $group_id = intval($group_id);
  285. $sql = "SELECT tag FROM $tag t INNER JOIN $table_group_rel_tag gt ON (gt.tag_id= t.id) WHERE gt.group_id = $group_id ";
  286. $res = Database::query($sql);
  287. $tags = array();
  288. if (Database::num_rows($res)>0) {
  289. while ($row = Database::fetch_array($res,'ASSOC')) {
  290. $tags[] = $row;
  291. }
  292. }
  293. if ($show_tag_links) {
  294. if (is_array($tags) && count($tags)>0) {
  295. foreach ($tags as $tag) {
  296. $tag_tmp[] = '<a href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tag['tag'].'">'.$tag['tag'].'</a>';
  297. }
  298. if (is_array($tags) && count($tags)>0) {
  299. $tags= implode(', ',$tag_tmp);
  300. }
  301. } else {
  302. $tags = '';
  303. }
  304. }
  305. return $tags;
  306. }
  307. /** Gets the inner join from users and group table
  308. * @return array Database::store_result of the result
  309. * @author Julio Montoya
  310. * */
  311. public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) {
  312. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  313. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  314. $user_id = intval($user_id);
  315. if ($relation_type == 0) {
  316. $where_relation_condition = '';
  317. } else {
  318. $relation_type = intval($relation_type);
  319. $where_relation_condition = "AND gu.relation_type = $relation_type ";
  320. }
  321. $sql = "SELECT g.picture_uri, g.name, g.description, g.id , gu.relation_type
  322. FROM $tbl_group g
  323. INNER JOIN $table_group_rel_user gu
  324. ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition ORDER BY created_on desc ";
  325. $result=Database::query($sql);
  326. $array = array();
  327. if (Database::num_rows($result) > 0) {
  328. while ($row = Database::fetch_array($result, 'ASSOC')) {
  329. if ($with_image) {
  330. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  331. $img = '<img src="'.$picture['file'].'" />';
  332. $row['picture_uri'] = $img;
  333. }
  334. $array[$row['id']] = $row;
  335. }
  336. }
  337. return $array;
  338. }
  339. /** Gets the inner join of users and group table
  340. * @param int quantity of records
  341. * @param bool show groups with image or not
  342. * @return array with group content
  343. * @author Julio Montoya
  344. * */
  345. public static function get_groups_by_popularity($num = 6, $with_image = true) {
  346. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  347. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  348. if (empty($num)) {
  349. $num = 6;
  350. } else {
  351. $num = intval($num);
  352. }
  353. // only show admins and readers
  354. $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
  355. $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
  356. FROM $tbl_group g
  357. INNER JOIN $table_group_rel_user gu
  358. ON gu.group_id = g.id $where_relation_condition GROUP BY g.id ORDER BY count DESC LIMIT $num";
  359. $result=Database::query($sql);
  360. $array = array();
  361. while ($row = Database::fetch_array($result, 'ASSOC')) {
  362. if ($with_image) {
  363. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  364. $img = '<img src="'.$picture['file'].'" />';
  365. $row['picture_uri'] = $img;
  366. }
  367. if (empty($row['id'])) {
  368. continue;
  369. }
  370. $array[$row['id']] = $row;
  371. }
  372. return $array;
  373. }
  374. /** Gets the last groups created
  375. * @param int quantity of records
  376. * @param bool show groups with image or not
  377. * @return array with group content
  378. * @author Julio Montoya
  379. * */
  380. public static function get_groups_by_age($num = 6, $with_image = true) {
  381. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  382. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  383. if (empty($num)) {
  384. $num = 6;
  385. } else {
  386. $num = intval($num);
  387. }
  388. $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
  389. $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
  390. FROM $tbl_group g INNER JOIN $table_group_rel_user gu ON gu.group_id = g.id
  391. $where_relation_condition
  392. ORDER BY created_on desc LIMIT $num ";
  393. $result=Database::query($sql);
  394. $array = array();
  395. while ($row = Database::fetch_array($result, 'ASSOC')) {
  396. if ($with_image) {
  397. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  398. $img = '<img src="'.$picture['file'].'" />';
  399. $row['picture_uri'] = $img;
  400. }
  401. if (empty($row['id'])) {
  402. continue;
  403. }
  404. $array[$row['id']] = $row;
  405. }
  406. return $array;
  407. }
  408. /**
  409. * Gets the group's members
  410. * @param int group id
  411. * @param bool show image or not of the group
  412. * @param array list of relation type use constants
  413. * @param int from value
  414. * @param int limit
  415. * @param array image configuration, i.e array('height'=>'20px', 'size'=> '20px')
  416. * @return array list of users in a group
  417. */
  418. public static function get_users_by_group($group_id, $with_image = false, $relation_type = array(), $from = null, $limit = null, $image_conf = array('size'=>USER_IMAGE_SIZE_MEDIUM,'height'=>80)) {
  419. $where = '';
  420. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  421. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  422. $group_id = intval($group_id);
  423. if (empty($group_id)){
  424. return array();
  425. }
  426. $limit_text = '';
  427. if (isset($from) && isset($limit)) {
  428. $from = intval($from);
  429. $limit = intval($limit);
  430. $limit_text = "LIMIT $from, $limit";
  431. }
  432. if (count($relation_type) == 0) {
  433. $where_relation_condition = '';
  434. } else {
  435. $new_relation_type = array();
  436. foreach($relation_type as $rel) {
  437. $rel = intval($rel);
  438. $new_relation_type[] ="'$rel'";
  439. }
  440. $relation_type = implode(',', $new_relation_type);
  441. if (!empty($relation_type))
  442. $where_relation_condition = "AND gu.relation_type IN ($relation_type) ";
  443. }
  444. $sql = "SELECT picture_uri as image, u.user_id, u.firstname, u.lastname, relation_type
  445. FROM $tbl_user u INNER JOIN $table_group_rel_user gu
  446. ON (gu.user_id = u.user_id)
  447. WHERE gu.group_id= $group_id $where_relation_condition
  448. ORDER BY relation_type, firstname $limit_text";
  449. $result = Database::query($sql);
  450. $array = array();
  451. while ($row = Database::fetch_array($result, 'ASSOC')) {
  452. if ($with_image) {
  453. $image_path = UserManager::get_user_picture_path_by_id($row['user_id'], 'web', false, true);
  454. $picture = UserManager::get_picture_user($row['user_id'], $image_path['file'], $image_conf['height'], $image_conf['size']);
  455. $row['image'] = '<img src="'.$picture['file'].'" '.$picture['style'].' />';
  456. }
  457. $array[$row['user_id']] = $row;
  458. }
  459. return $array;
  460. }
  461. /**
  462. * Gets all the members of a group no matter the relationship for more specifications use get_users_by_group
  463. * @param int group id
  464. * @return array
  465. */
  466. public static function get_all_users_by_group($group_id)
  467. {
  468. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  469. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  470. $group_id = intval($group_id);
  471. if (empty($group_id)){
  472. return array();
  473. }
  474. $sql="SELECT u.user_id, u.firstname, u.lastname, relation_type FROM $tbl_user u
  475. INNER JOIN $table_group_rel_user gu
  476. ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id ORDER BY relation_type, firstname";
  477. $result=Database::query($sql);
  478. $array = array();
  479. while ($row = Database::fetch_array($result, 'ASSOC')) {
  480. $array[$row['user_id']] = $row;
  481. }
  482. return $array;
  483. }
  484. /**
  485. * Gets the relationship between a group and a User
  486. * @author Julio Montoya
  487. * @param int user id
  488. * @param int group_id
  489. * @return int 0 if there are not relationship otherwise returns the user group
  490. * */
  491. public static function get_user_group_role($user_id, $group_id)
  492. {
  493. $table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  494. $return_value = 0;
  495. if (!empty($user_id) && !empty($group_id)) {
  496. $sql = "SELECT relation_type FROM $table_group_rel_user WHERE group_id = ".intval($group_id)." AND user_id = ".intval($user_id)." ";
  497. $result = Database::query($sql);
  498. if (Database::num_rows($result)>0) {
  499. $row = Database::fetch_array($result,'ASSOC');
  500. $return_value = $row['relation_type'];
  501. }
  502. }
  503. return $return_value;
  504. }
  505. /**
  506. * Add a user into a group
  507. * @author Julio Montoya
  508. * @param user_id
  509. * @param url_id
  510. * @return boolean true if success
  511. * */
  512. public static function add_user_to_group($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER) {
  513. $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  514. if (!empty($user_id) && !empty($group_id)) {
  515. $role = self::get_user_group_role($user_id,$group_id);
  516. if ($role == 0) {
  517. $sql = "INSERT INTO $table_url_rel_group
  518. SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
  519. $result = Database::query($sql);
  520. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  521. //if somebody already invited me I can be added
  522. self::update_user_role($user_id, $group_id, GROUP_USER_PERMISSION_READER);
  523. }
  524. }
  525. return $result;
  526. }
  527. /**
  528. * Add a group of users into a group of URLs
  529. * @author Julio Montoya
  530. * @param array of user_ids
  531. * @param array of url_ids
  532. * */
  533. public static function add_users_to_groups($user_list, $group_list, $relation_type = GROUP_USER_PERMISSION_READER) {
  534. $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  535. $result_array = array();
  536. $relation_type = intval($relation_type);
  537. if (is_array($user_list) && is_array($group_list)) {
  538. foreach ($group_list as $group_id) {
  539. foreach ($user_list as $user_id) {
  540. $role = self::get_user_group_role($user_id,$group_id);
  541. if ($role == 0) {
  542. $sql = "INSERT INTO $table_url_rel_group
  543. SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
  544. $result = Database::query($sql);
  545. if ($result)
  546. $result_array[$group_id][$user_id]=1;
  547. else
  548. $result_array[$group_id][$user_id]=0;
  549. }
  550. }
  551. }
  552. }
  553. return $result_array;
  554. }
  555. /**
  556. * Deletes a group and user relationship
  557. * @author Julio Montoya
  558. * @param int user id
  559. * @param int relation type (optional)
  560. * @return boolean true if success
  561. * */
  562. public static function delete_users($group_id,$relation_type='')
  563. {
  564. $table_ = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  565. $condition_relation = "";
  566. if (!empty($relation_type)) {
  567. $relation_type = intval($relation_type);
  568. $condition_relation = " AND relation_type = '$relation_type'";
  569. }
  570. $sql = "DELETE FROM $table_ WHERE group_id = ".intval($group_id).$condition_relation;
  571. $result = Database::query($sql);
  572. return $result;
  573. }
  574. /**
  575. * Deletes an url and session relationship
  576. * @author Julio Montoya
  577. * @param char course code
  578. * @param int url id
  579. * @return boolean true if success
  580. * */
  581. public static function delete_user_rel_group($user_id, $group_id) {
  582. $table = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  583. $sql= "DELETE FROM $table WHERE user_id = ".intval($user_id)." AND group_id=".intval($group_id)." ";
  584. $result = Database::query($sql);
  585. return $result;
  586. }
  587. /**
  588. * Updates the group_rel_user table with a given user and group ids
  589. * @author Julio Montoya
  590. * @param int user id
  591. * @param int group id
  592. * @param int relation type
  593. * */
  594. public static function update_user_role($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER)
  595. {
  596. $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  597. $group_id = intval($group_id);
  598. $user_id = intval($user_id);
  599. $sql = "UPDATE $table_group_rel_user
  600. SET relation_type = ".intval($relation_type)." WHERE user_id = $user_id AND group_id = $group_id" ;
  601. Database::query($sql);
  602. }
  603. public static function get_group_admin_list($user_id, $group_id)
  604. {
  605. $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  606. $group_id = intval($group_id);
  607. $user_id = intval($user_id);
  608. $sql = "SELECT user_id FROM $table_group_rel_user WHERE
  609. relation_type = ".GROUP_USER_PERMISSION_ADMIN." AND user_id = $user_id AND group_id = $group_id" ;
  610. $result = Database::query($sql);
  611. }
  612. public static function get_all_group_tags($tag, $from=0, $number_of_items=10) {
  613. // database table definition
  614. $group_table = Database::get_main_table(TABLE_MAIN_GROUP);
  615. $table_tag = Database::get_main_table(TABLE_MAIN_TAG);
  616. $table_group_tag_values = Database::get_main_table(TABLE_MAIN_GROUP_REL_TAG);
  617. //default field_id == 1
  618. $field_id = 5;
  619. $tag = Database::escape_string($tag);
  620. $from = intval($from);
  621. $number_of_items = intval($number_of_items);
  622. // all the information of the field
  623. $sql = "SELECT g.id, g.name, g.description, g.picture_uri FROM $table_tag t INNER JOIN $table_group_tag_values tv ON (tv.tag_id=t.id)
  624. INNER JOIN $group_table g ON(tv.group_id =g.id)
  625. WHERE tag LIKE '$tag%' AND field_id= $field_id ORDER BY tag";
  626. $sql .= " LIMIT $from,$number_of_items";
  627. $result = Database::query($sql);
  628. $return = array();
  629. if (Database::num_rows($result)> 0) {
  630. while ($row = Database::fetch_array($result,'ASSOC')) {
  631. $return[$row['id']] = $row;
  632. }
  633. }
  634. $keyword = $tag;
  635. $sql = "SELECT g.id, g.name, g.description, g.url, g.picture_uri FROM $group_table g";
  636. //@todo implement groups + multiple urls
  637. /*
  638. global $_configuration;
  639. if ($_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) {
  640. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  641. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  642. }*/
  643. //@todo implement visibility
  644. if (isset ($keyword)) {
  645. $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
  646. }
  647. $direction = 'ASC';
  648. if (!in_array($direction, array('ASC','DESC'))) {
  649. $direction = 'ASC';
  650. }
  651. //$column = intval($column);
  652. $from = intval($from);
  653. $number_of_items = intval($number_of_items);
  654. //$sql .= " ORDER BY col$column $direction ";
  655. $sql .= " LIMIT $from,$number_of_items";
  656. $res = Database::query($sql);
  657. if (Database::num_rows($res)> 0) {
  658. while ($row = Database::fetch_array($res,'ASSOC')) {
  659. if (!in_array($row['id'], $return)) {
  660. $return[$row['id']] = $row;
  661. }
  662. }
  663. }
  664. return $return;
  665. }
  666. /**
  667. * Creates new group pictures in various sizes of a user, or deletes user pfotos.
  668. * Note: This method relies on configuration setting from dokeos/main/inc/conf/profile.conf.php
  669. * @param int The group id
  670. * @param string $file The common file name for the newly created pfotos. It will be checked and modified for compatibility with the file system.
  671. * If full name is provided, path component is ignored.
  672. * If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() as the prefered way for deletion.
  673. * @param string $source_file The full system name of the image from which user photos will be created.
  674. * @return string/bool Returns the resulting common file name of created images which usually should be stored in database.
  675. * When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE.
  676. */
  677. public static function update_group_picture($group_id, $file = null, $source_file = null) {
  678. // Validation 1.
  679. if (empty($group_id)) {
  680. return false;
  681. }
  682. $delete = empty($file);
  683. if (empty($source_file)) {
  684. $source_file = $file;
  685. }
  686. // Configuration options about user photos.
  687. require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
  688. // User-reserved directory where photos have to be placed.
  689. $path_info = self::get_group_picture_path_by_id($group_id, 'system', true);
  690. $path = $path_info['dir'];
  691. // If this directory does not exist - we create it.
  692. if (!file_exists($path)) {
  693. @mkdir($path, api_get_permissions_for_new_directories(), true);
  694. }
  695. // The old photos (if any).
  696. $old_file = $path_info['file'];
  697. // Let us delete them.
  698. if (!empty($old_file)) {
  699. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
  700. $prefix = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_';
  701. @rename($path.'small_'.$old_file, $path.$prefix.'small_'.$old_file);
  702. @rename($path.'medium_'.$old_file, $path.$prefix.'medium_'.$old_file);
  703. @rename($path.'big_'.$old_file, $path.$prefix.'big_'.$old_file);
  704. @rename($path.$old_file, $path.$prefix.$old_file);
  705. } else {
  706. @unlink($path.'small_'.$old_file);
  707. @unlink($path.'medium_'.$old_file);
  708. @unlink($path.'big_'.$old_file);
  709. @unlink($path.$old_file);
  710. }
  711. }
  712. // Exit if only deletion has been requested. Return an empty picture name.
  713. if ($delete) {
  714. return '';
  715. }
  716. // Validation 2.
  717. $allowed_types = array('jpg', 'jpeg', 'png', 'gif');
  718. $file = str_replace('\\', '/', $file);
  719. $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file;
  720. $extension = strtolower(substr(strrchr($filename, '.'), 1));
  721. if (!in_array($extension, $allowed_types)) {
  722. return false;
  723. }
  724. // This is the common name for the new photos.
  725. if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) {
  726. $old_extension = strtolower(substr(strrchr($old_file, '.'), 1));
  727. $filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file;
  728. $filename = (substr($filename, -1) == '.') ? $filename.$extension : $filename.'.'.$extension;
  729. } else {
  730. $filename = replace_dangerous_char($filename);
  731. if (PREFIX_IMAGE_FILENAME_WITH_UID) {
  732. $filename = uniqid('').'_'.$filename;
  733. }
  734. // We always prefix user photos with user ids, so on setting
  735. // api_get_setting('split_users_upload_directory') === 'true'
  736. // the correspondent directories to be found successfully.
  737. $filename = $group_id.'_'.$filename;
  738. }
  739. // Storing the new photos in 4 versions with various sizes.
  740. $small = self::resize_picture($source_file, 22);
  741. $medium = self::resize_picture($source_file, 85);
  742. $normal = self::resize_picture($source_file, 200);
  743. $big = new Image($source_file); // This is the original picture.
  744. $ok = $small->send_image($path.'small_'.$filename)
  745. && $medium->send_image($path.'medium_'.$filename)
  746. && $normal->send_image($path.'big_'.$filename)
  747. && $big->send_image($path.$filename);
  748. return $ok ? $filename : false;
  749. }
  750. /**
  751. * Gets the group picture URL or path from group ID (returns an array).
  752. * The return format is a complete path, enabling recovery of the directory
  753. * with dirname() or the file with basename(). This also works for the
  754. * functions dealing with the user's productions, as they are located in
  755. * the same directory.
  756. * @param integer User ID
  757. * @param string Type of path to return (can be 'none', 'system', 'rel', 'web')
  758. * @param bool Whether we want to have the directory name returned 'as if' there was a file or not (in the case we want to know which directory to create - otherwise no file means no split subdir)
  759. * @param bool If we want that the function returns the /main/img/unknown.jpg image set it at true
  760. * @return array Array of 2 elements: 'dir' and 'file' which contain the dir and file as the name implies if image does not exist it will return the unknow image if anonymous parameter is true if not it returns an empty er's
  761. */
  762. public static function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) {
  763. switch ($type) {
  764. case 'system': // Base: absolute system path.
  765. $base = api_get_path(SYS_CODE_PATH);
  766. break;
  767. case 'rel': // Base: semi-absolute web path (no server base).
  768. $base = api_get_path(REL_CODE_PATH);
  769. break;
  770. case 'web': // Base: absolute web path.
  771. $base = api_get_path(WEB_CODE_PATH);
  772. break;
  773. case 'none':
  774. default: // Base: empty, the result path below will be relative.
  775. $base = '';
  776. }
  777. if (empty($id) || empty($type)) {
  778. return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
  779. }
  780. $id = intval($id);
  781. $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
  782. $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id;
  783. $res = Database::query($sql);
  784. if (!Database::num_rows($res)) {
  785. return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
  786. }
  787. $user = Database::fetch_array($res);
  788. $picture_filename = trim($user['picture_uri']);
  789. if (api_get_setting('split_users_upload_directory') === 'true') {
  790. if (!empty($picture_filename)) {
  791. $dir = $base.'upload/users/groups/'.substr($picture_filename, 0, 1).'/'.$id.'/';
  792. } elseif ($preview) {
  793. $dir = $base.'upload/users/groups/'.substr((string)$id, 0, 1).'/'.$id.'/';
  794. } else {
  795. $dir = $base.'upload/users/groups/'.$id.'/';
  796. }
  797. } else {
  798. $dir = $base.'upload/users/groups/'.$id.'/';
  799. }
  800. if (empty($picture_filename) && $anonymous) {
  801. return array('dir' => $base.'img/', 'file' => 'unknown.jpg');
  802. }
  803. return array('dir' => $dir, 'file' => $picture_filename);
  804. }
  805. /**
  806. * Resize a picture
  807. *
  808. * @param string file picture
  809. * @param int size in pixels
  810. * @return obj image object
  811. */
  812. public static function resize_picture($file, $max_size_for_picture) {
  813. $temp = new Image($file);
  814. $picture_infos = api_getimagesize($file);
  815. if ($picture_infos['width'] > $max_size_for_picture) {
  816. $thumbwidth = $max_size_for_picture;
  817. if (empty($thumbwidth) or $thumbwidth == 0) {
  818. $thumbwidth = $max_size_for_picture;
  819. }
  820. $new_height = round(($thumbwidth / $picture_infos['width']) * $picture_infos['height']);
  821. if ($new_height > $max_size_for_picture)
  822. $new_height = $thumbwidth;
  823. $temp->resize($thumbwidth, $new_height, 0);
  824. }
  825. return $temp;
  826. }
  827. /**
  828. * Gets the current group image
  829. * @param string group id
  830. * @param string picture group name
  831. * @param string height
  832. * @param string picture size it can be small_, medium_ or big_
  833. * @param string style css
  834. * @return array with the file and the style of an image i.e $array['file'] $array['style']
  835. */
  836. public static function get_picture_group($id, $picture_file, $height, $size_picture = GROUP_IMAGE_SIZE_MEDIUM , $style = '') {
  837. $patch_profile = 'upload/users/groups/';
  838. $picture = array();
  839. $picture['style'] = $style;
  840. if ($picture_file == 'unknown.jpg') {
  841. $picture['file'] = api_get_path(WEB_CODE_PATH).'img/'.$picture_file;
  842. return $picture;
  843. }
  844. switch ($size_picture) {
  845. case GROUP_IMAGE_SIZE_ORIGINAL :
  846. $size_picture = '';
  847. break;
  848. case GROUP_IMAGE_SIZE_BIG :
  849. $size_picture = 'big_';
  850. break;
  851. case GROUP_IMAGE_SIZE_MEDIUM :
  852. $size_picture = 'medium_';
  853. break;
  854. case GROUP_IMAGE_SIZE_SMALL :
  855. $size_picture = 'small_';
  856. break;
  857. default:
  858. $size_picture = 'medium_';
  859. }
  860. $image_array_sys = self::get_group_picture_path_by_id($id, 'system', false, true);
  861. $image_array = self::get_group_picture_path_by_id($id, 'web', false, true);
  862. $file = $image_array_sys['dir'].$size_picture.$picture_file;
  863. if (file_exists($file)) {
  864. $picture['file'] = $image_array['dir'].$size_picture.$picture_file;
  865. $picture['style'] = '';
  866. if ($height > 0) {
  867. $dimension = api_getimagesize($picture['file']);
  868. $margin = (($height - $dimension['width']) / 2);
  869. //@ todo the padding-top should not be here
  870. $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension['width'].'px; height:'.$dimension['height'].';" ';
  871. }
  872. } else {
  873. //$file = api_get_path(SYS_CODE_PATH).$patch_profile.$user_id.'/'.$picture_file;
  874. $file = $image_array_sys['dir'].$picture_file;
  875. if (file_exists($file) && !is_dir($file)) {
  876. $picture['file'] = $image_array['dir'].$picture_file;
  877. } else {
  878. $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_group.png';
  879. }
  880. }
  881. return $picture;
  882. }
  883. public static function delete_group_picture($group_id) {
  884. return self::update_group_picture($group_id);
  885. }
  886. public static function is_group_admin($group_id, $user_id = 0) {
  887. if (empty($user_id)) {
  888. $user_id = api_get_user_id();
  889. }
  890. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  891. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN))) {
  892. return true;
  893. } else {
  894. return false;
  895. }
  896. }
  897. public static function is_group_moderator($group_id, $user_id = 0) {
  898. if (empty($user_id)) {
  899. $user_id = api_get_user_id();
  900. }
  901. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  902. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  903. return true;
  904. } else {
  905. return false;
  906. }
  907. }
  908. public static function is_group_member($group_id, $user_id = 0) {
  909. if (empty($user_id)) {
  910. $user_id = api_get_user_id();
  911. }
  912. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  913. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_HRM))) {
  914. return true;
  915. } else {
  916. return false;
  917. }
  918. }
  919. /**
  920. * Shows the left column of the group page
  921. * @param int group id
  922. * @param int user id
  923. *
  924. */
  925. public static function show_group_column_information($group_id, $user_id, $show = '') {
  926. global $relation_group_title, $my_group_role;
  927. $html = '';
  928. $group_info = GroupPortalManager::get_group_data($group_id);
  929. //$picture = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,GROUP_IMAGE_SIZE_MEDIUM);
  930. //$big_image = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],'',GROUP_IMAGE_SIZE_BIG);
  931. //$tags = GroupPortalManager::get_group_tags($group_id, true);
  932. //$groups_by_user = GroupPortalManager::get_groups_by_user($user_id, 0);
  933. //my relation with the group is set here
  934. $my_group_role = self::get_user_group_role($user_id, $group_id);
  935. //@todo this must be move to default.css for dev use only
  936. $html .= '<style>
  937. #group_members { width:270px; height:300px; overflow-x:none; overflow-y: auto;}
  938. .group_member_item { width:100px; height:130px; float:left; margin:5px 5px 15px 5px; }
  939. .group_member_picture { display:block;
  940. margin:0;
  941. overflow:hidden; };
  942. </style>';
  943. //Loading group permission
  944. $links = '';
  945. switch ($my_group_role) {
  946. case GROUP_USER_PERMISSION_READER:
  947. // I'm just a reader
  948. $relation_group_title = get_lang('IAmAReader');
  949. $links .= '<li><a href="group_invitation.php?id='.$group_id.'">'. Display::return_icon('invitation_friend.png', get_lang('InviteFriends'), array('hspace'=>'6')).'<span class="'.($show=='invite_friends'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('InviteFriends').'</span></a></li>';
  950. $links .= '<li><a href="groups.php?id='.$group_id.'&action=leave&u='.api_get_user_id().'">'. Display::return_icon('group_leave.png', get_lang('LeaveGroup'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('LeaveGroup').'</span></a></li>';
  951. break;
  952. case GROUP_USER_PERMISSION_ADMIN:
  953. $relation_group_title = get_lang('IAmAnAdmin');
  954. $links .= '<li><a href="group_edit.php?id='.$group_id.'">'. Display::return_icon('group_edit.png', get_lang('EditGroup'), array('hspace'=>'6')).'<span class="'.($show=='group_edit'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('EditGroup').'</span></a></li>';
  955. $links .= '<li><a href="group_waiting_list.php?id='.$group_id.'">'. Display::return_icon('waiting_list.png', get_lang('WaitingList'), array('hspace'=>'6')).'<span class="'.($show=='waiting_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('WaitingList').'</span></a></li>';
  956. $links .= '<li><a href="group_invitation.php?id='.$group_id.'">'. Display::return_icon('invitation_friend.png', get_lang('InviteFriends'), array('hspace'=>'6')).'<span class="'.($show=='invite_friends'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('InviteFriends').'</span></a></li>';
  957. $links .= '<li><a href="groups.php?id='.$group_id.'&action=leave&u='.api_get_user_id().'">'. Display::return_icon('group_leave.png', get_lang('LeaveGroup'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('LeaveGroup').'</span></a></li>';
  958. break;
  959. case GROUP_USER_PERMISSION_PENDING_INVITATION:
  960. // $links .= '<li><a href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.Display::return_icon('addd.gif', get_lang('YouHaveBeenInvitedJoinNow'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('YouHaveBeenInvitedJoinNow').'</span></a></li>';
  961. break;
  962. case GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER:
  963. $relation_group_title = get_lang('WaitingForAdminResponse');
  964. break;
  965. case GROUP_USER_PERMISSION_MODERATOR:
  966. $relation_group_title = get_lang('IAmAModerator');
  967. //$links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('compose_message.png', get_lang('NewTopic'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('NewTopic').'</span></a></li>';
  968. //$links .= '<li><a href="groups.php?id='.$group_id.'">'. Display::return_icon('message_list.png', get_lang('MessageList'), array('hspace'=>'6')).'<span class="'.($show=='messages_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MessageList').'</span></a></li>';
  969. //$links .= '<li><a href="group_members.php?id='.$group_id.'">'. Display::return_icon('member_list.png', get_lang('MemberList'), array('hspace'=>'6')).'<span class="'.($show=='member_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MemberList').'</span></a></li>';
  970. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  971. $links .= '<li><a href="group_waiting_list.php?id='.$group_id.'">'. Display::return_icon('waiting_list.png', get_lang('WaitingList'), array('hspace'=>'6')).'<span class="'.($show=='waiting_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('WaitingList').'</span></a></li>';
  972. }
  973. $links .= '<li><a href="group_invitation.php?id='.$group_id.'">'. Display::return_icon('invitation_friend.png', get_lang('InviteFriends'), array('hspace'=>'6')).'<span class="'.($show=='invite_friends'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('InviteFriends').'</span></a></li>';
  974. $links .= '<li><a href="groups.php?id='.$group_id.'&action=leave&u='.api_get_user_id().'">'. Display::return_icon('group_leave.png', get_lang('LeaveGroup'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('LeaveGroup').'</span></a></li>';
  975. break;
  976. case GROUP_USER_PERMISSION_HRM:
  977. $relation_group_title = get_lang('IAmAHRM');
  978. $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="ajax" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('compose_message.png', get_lang('NewTopic'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('NewTopic').'</span></a></li>';
  979. $links .= '<li><a href="groups.php?id='.$group_id.'">'. Display::return_icon('message_list.png', get_lang('MessageList'), array('hspace'=>'6')).'<span class="'.($show=='messages_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MessageList').'</span></a></li>';
  980. $links .= '<li><a href="group_invitation.php?id='.$group_id.'">'. Display::return_icon('invitation_friend.png', get_lang('InviteFriends'), array('hspace'=>'6')).'<span class="'.($show=='invite_friends'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('InviteFriends').'</span></a></li>';
  981. $links .= '<li><a href="group_members.php?id='.$group_id.'">'. Display::return_icon('member_list.png', get_lang('MemberList'), array('hspace'=>'6')).'<span class="'.($show=='member_list'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MemberList').'</span></a></li>';
  982. $links .= '<li><a href="groups.php?id='.$group_id.'&action=leave&u='.api_get_user_id().'">'. Display::return_icon('delete_data.gif', get_lang('LeaveGroup'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('LeaveGroup').'</span></a></li>';
  983. break;
  984. default:
  985. //$links .= '<li><a href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.Display::return_icon('addd.gif', get_lang('JoinGroup'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('JoinGroup').'</a></span></li>';
  986. break;
  987. }
  988. if (!empty($links)) {
  989. $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">';
  990. if (!empty($group_info['description'])) {
  991. $html .= Display::tag('li', Security::remove_XSS($group_info['description'], STUDENT, true), array('class'=>'group_description'));
  992. }
  993. $html .= $links;
  994. $html .= '</ul></div>';
  995. }
  996. return $html;
  997. }
  998. function delete_topic($group_id, $topic_id) {
  999. $table_message = Database::get_main_table(TABLE_MESSAGE);
  1000. $topic_id = intval($topic_id);
  1001. $group_id = intval($group_id);
  1002. $sql = "UPDATE $table_message SET msg_status=3 WHERE group_id = $group_id AND (id = '$topic_id' OR parent_id = $topic_id) ";
  1003. Database::query($sql);
  1004. }
  1005. }