group_portal_manager.lib.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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. $tag = Database :: get_main_table(TABLE_MAIN_TAG);
  282. $table_group_rel_tag = Database :: get_main_table(TABLE_MAIN_GROUP_REL_TAG);
  283. $group_id = intval($group_id);
  284. $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 ";
  285. $res = Database::query($sql);
  286. $tags = array();
  287. if (Database::num_rows($res)>0) {
  288. while ($row = Database::fetch_array($res,'ASSOC')) {
  289. $tags[] = $row;
  290. }
  291. }
  292. if ($show_tag_links) {
  293. if (is_array($tags) && count($tags)>0) {
  294. foreach ($tags as $tag) {
  295. $tag_tmp[] = '<a href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tag['tag'].'">'.$tag['tag'].'</a>';
  296. }
  297. if (is_array($tags) && count($tags)>0) {
  298. $tags= implode(', ',$tag_tmp);
  299. }
  300. } else {
  301. $tags = '';
  302. }
  303. }
  304. return $tags;
  305. }
  306. /** Gets the inner join from users and group table
  307. * @return array Database::store_result of the result
  308. * @author Julio Montoya
  309. * */
  310. public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) {
  311. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  312. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  313. $user_id = intval($user_id);
  314. if ($relation_type == 0) {
  315. $where_relation_condition = '';
  316. } else {
  317. $relation_type = intval($relation_type);
  318. $where_relation_condition = "AND gu.relation_type = $relation_type ";
  319. }
  320. $sql = "SELECT g.picture_uri, g.name, g.description, g.id , gu.relation_type
  321. FROM $tbl_group g
  322. INNER JOIN $table_group_rel_user gu
  323. ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition ORDER BY created_on desc ";
  324. $result=Database::query($sql);
  325. $array = array();
  326. if (Database::num_rows($result) > 0) {
  327. while ($row = Database::fetch_array($result, 'ASSOC')) {
  328. if ($with_image) {
  329. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  330. $img = '<img src="'.$picture['file'].'" />';
  331. $row['picture_uri'] = $img;
  332. }
  333. $array[$row['id']] = $row;
  334. }
  335. }
  336. return $array;
  337. }
  338. /** Gets the inner join of users and group table
  339. * @param int quantity of records
  340. * @param bool show groups with image or not
  341. * @return array with group content
  342. * @author Julio Montoya
  343. * */
  344. public static function get_groups_by_popularity($num = 6, $with_image = true) {
  345. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  346. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  347. if (empty($num)) {
  348. $num = 6;
  349. } else {
  350. $num = intval($num);
  351. }
  352. // only show admins and readers
  353. $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
  354. $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
  355. FROM $tbl_group g
  356. INNER JOIN $table_group_rel_user gu
  357. ON gu.group_id = g.id $where_relation_condition GROUP BY g.id ORDER BY count DESC LIMIT $num";
  358. $result=Database::query($sql);
  359. $array = array();
  360. while ($row = Database::fetch_array($result, 'ASSOC')) {
  361. if ($with_image) {
  362. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  363. $img = '<img src="'.$picture['file'].'" />';
  364. $row['picture_uri'] = $img;
  365. }
  366. if (empty($row['id'])) {
  367. continue;
  368. }
  369. $array[$row['id']] = $row;
  370. }
  371. return $array;
  372. }
  373. /** Gets the last groups created
  374. * @param int quantity of records
  375. * @param bool show groups with image or not
  376. * @return array with group content
  377. * @author Julio Montoya
  378. * */
  379. public static function get_groups_by_age($num = 6, $with_image = true) {
  380. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  381. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  382. if (empty($num)) {
  383. $num = 6;
  384. } else {
  385. $num = intval($num);
  386. }
  387. $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
  388. $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
  389. FROM $tbl_group g INNER JOIN $table_group_rel_user gu ON gu.group_id = g.id
  390. $where_relation_condition
  391. ORDER BY created_on desc LIMIT $num ";
  392. $result=Database::query($sql);
  393. $array = array();
  394. while ($row = Database::fetch_array($result, 'ASSOC')) {
  395. if ($with_image) {
  396. $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
  397. $img = '<img src="'.$picture['file'].'" />';
  398. $row['picture_uri'] = $img;
  399. }
  400. if (empty($row['id'])) {
  401. continue;
  402. }
  403. $array[$row['id']] = $row;
  404. }
  405. return $array;
  406. }
  407. /**
  408. * Gets the group's members
  409. * @param int group id
  410. * @param bool show image or not of the group
  411. * @param array list of relation type use constants
  412. * @param int from value
  413. * @param int limit
  414. * @param array image configuration, i.e array('height'=>'20px', 'size'=> '20px')
  415. * @return array list of users in a group
  416. */
  417. 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)) {
  418. $where = '';
  419. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  420. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  421. $group_id = intval($group_id);
  422. if (empty($group_id)){
  423. return array();
  424. }
  425. $limit_text = '';
  426. if (isset($from) && isset($limit)) {
  427. $from = intval($from);
  428. $limit = intval($limit);
  429. $limit_text = "LIMIT $from, $limit";
  430. }
  431. if (count($relation_type) == 0) {
  432. $where_relation_condition = '';
  433. } else {
  434. $new_relation_type = array();
  435. foreach($relation_type as $rel) {
  436. $rel = intval($rel);
  437. $new_relation_type[] ="'$rel'";
  438. }
  439. $relation_type = implode(',', $new_relation_type);
  440. if (!empty($relation_type))
  441. $where_relation_condition = "AND gu.relation_type IN ($relation_type) ";
  442. }
  443. $sql = "SELECT picture_uri as image, u.user_id, u.firstname, u.lastname, relation_type
  444. FROM $tbl_user u INNER JOIN $table_group_rel_user gu
  445. ON (gu.user_id = u.user_id)
  446. WHERE gu.group_id= $group_id $where_relation_condition
  447. ORDER BY relation_type, firstname $limit_text";
  448. $result = Database::query($sql);
  449. $array = array();
  450. while ($row = Database::fetch_array($result, 'ASSOC')) {
  451. if ($with_image) {
  452. $image_path = UserManager::get_user_picture_path_by_id($row['user_id'], 'web', false, true);
  453. $picture = UserManager::get_picture_user($row['user_id'], $image_path['file'], $image_conf['height'], $image_conf['size']);
  454. $row['image'] = '<img src="'.$picture['file'].'" '.$picture['style'].' />';
  455. }
  456. $array[$row['user_id']] = $row;
  457. }
  458. return $array;
  459. }
  460. /**
  461. * Gets all the members of a group no matter the relationship for more specifications use get_users_by_group
  462. * @param int group id
  463. * @return array
  464. */
  465. public static function get_all_users_by_group($group_id)
  466. {
  467. $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
  468. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  469. $group_id = intval($group_id);
  470. if (empty($group_id)){
  471. return array();
  472. }
  473. $sql="SELECT u.user_id, u.firstname, u.lastname, relation_type FROM $tbl_user u
  474. INNER JOIN $table_group_rel_user gu
  475. ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id ORDER BY relation_type, firstname";
  476. $result=Database::query($sql);
  477. $array = array();
  478. while ($row = Database::fetch_array($result, 'ASSOC')) {
  479. $array[$row['user_id']] = $row;
  480. }
  481. return $array;
  482. }
  483. /**
  484. * Gets the relationship between a group and a User
  485. * @author Julio Montoya
  486. * @param int user id
  487. * @param int group_id
  488. * @return int 0 if there are not relationship otherwise returns the user group
  489. * */
  490. public static function get_user_group_role($user_id, $group_id)
  491. {
  492. $table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  493. $return_value = 0;
  494. if (!empty($user_id) && !empty($group_id)) {
  495. $sql = "SELECT relation_type FROM $table_group_rel_user WHERE group_id = ".intval($group_id)." AND user_id = ".intval($user_id)." ";
  496. $result = Database::query($sql);
  497. if (Database::num_rows($result)>0) {
  498. $row = Database::fetch_array($result,'ASSOC');
  499. $return_value = $row['relation_type'];
  500. }
  501. }
  502. return $return_value;
  503. }
  504. /**
  505. * Add a user into a group
  506. * @author Julio Montoya
  507. * @param user_id
  508. * @param url_id
  509. * @return boolean true if success
  510. * */
  511. public static function add_user_to_group($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER) {
  512. $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  513. if (!empty($user_id) && !empty($group_id)) {
  514. $role = self::get_user_group_role($user_id,$group_id);
  515. if ($role == 0) {
  516. $sql = "INSERT INTO $table_url_rel_group
  517. SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
  518. $result = Database::query($sql);
  519. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  520. //if somebody already invited me I can be added
  521. self::update_user_role($user_id, $group_id, GROUP_USER_PERMISSION_READER);
  522. }
  523. }
  524. return $result;
  525. }
  526. /**
  527. * Add a group of users into a group of URLs
  528. * @author Julio Montoya
  529. * @param array of user_ids
  530. * @param array of url_ids
  531. * */
  532. public static function add_users_to_groups($user_list, $group_list, $relation_type = GROUP_USER_PERMISSION_READER) {
  533. $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  534. $result_array = array();
  535. $relation_type = intval($relation_type);
  536. if (is_array($user_list) && is_array($group_list)) {
  537. foreach ($group_list as $group_id) {
  538. foreach ($user_list as $user_id) {
  539. $role = self::get_user_group_role($user_id,$group_id);
  540. if ($role == 0) {
  541. $sql = "INSERT INTO $table_url_rel_group
  542. SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
  543. $result = Database::query($sql);
  544. if ($result)
  545. $result_array[$group_id][$user_id]=1;
  546. else
  547. $result_array[$group_id][$user_id]=0;
  548. }
  549. }
  550. }
  551. }
  552. return $result_array;
  553. }
  554. /**
  555. * Deletes a group and user relationship
  556. * @author Julio Montoya
  557. * @param int user id
  558. * @param int relation type (optional)
  559. * @return boolean true if success
  560. * */
  561. public static function delete_users($group_id,$relation_type='')
  562. {
  563. $table_ = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  564. $condition_relation = "";
  565. if (!empty($relation_type)) {
  566. $relation_type = intval($relation_type);
  567. $condition_relation = " AND relation_type = '$relation_type'";
  568. }
  569. $sql = "DELETE FROM $table_ WHERE group_id = ".intval($group_id).$condition_relation;
  570. $result = Database::query($sql);
  571. return $result;
  572. }
  573. /**
  574. * Deletes an url and session relationship
  575. * @author Julio Montoya
  576. * @param char course code
  577. * @param int url id
  578. * @return boolean true if success
  579. * */
  580. public static function delete_user_rel_group($user_id, $group_id) {
  581. $table = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  582. $sql= "DELETE FROM $table WHERE user_id = ".intval($user_id)." AND group_id=".intval($group_id)." ";
  583. $result = Database::query($sql);
  584. return $result;
  585. }
  586. /**
  587. * Updates the group_rel_user table with a given user and group ids
  588. * @author Julio Montoya
  589. * @param int user id
  590. * @param int group id
  591. * @param int relation type
  592. * */
  593. public static function update_user_role($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER)
  594. {
  595. $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  596. $group_id = intval($group_id);
  597. $user_id = intval($user_id);
  598. $sql = "UPDATE $table_group_rel_user
  599. SET relation_type = ".intval($relation_type)." WHERE user_id = $user_id AND group_id = $group_id" ;
  600. Database::query($sql);
  601. }
  602. public static function get_group_admin_list($user_id, $group_id)
  603. {
  604. $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
  605. $group_id = intval($group_id);
  606. $user_id = intval($user_id);
  607. $sql = "SELECT user_id FROM $table_group_rel_user WHERE
  608. relation_type = ".GROUP_USER_PERMISSION_ADMIN." AND user_id = $user_id AND group_id = $group_id" ;
  609. $result = Database::query($sql);
  610. }
  611. public static function get_all_group_tags($tag, $from=0, $number_of_items=10) {
  612. // database table definition
  613. $group_table = Database::get_main_table(TABLE_MAIN_GROUP);
  614. $table_tag = Database::get_main_table(TABLE_MAIN_TAG);
  615. $table_group_tag_values = Database::get_main_table(TABLE_MAIN_GROUP_REL_TAG);
  616. //default field_id == 1
  617. $field_id = 5;
  618. $tag = Database::escape_string($tag);
  619. $from = intval($from);
  620. $number_of_items = intval($number_of_items);
  621. // all the information of the field
  622. $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)
  623. INNER JOIN $group_table g ON(tv.group_id =g.id)
  624. WHERE tag LIKE '$tag%' AND field_id= $field_id ORDER BY tag";
  625. $sql .= " LIMIT $from,$number_of_items";
  626. $result = Database::query($sql);
  627. $return = array();
  628. if (Database::num_rows($result)> 0) {
  629. while ($row = Database::fetch_array($result,'ASSOC')) {
  630. $return[$row['id']] = $row;
  631. }
  632. }
  633. $keyword = $tag;
  634. $sql = "SELECT g.id, g.name, g.description, g.url, g.picture_uri FROM $group_table g";
  635. //@todo implement groups + multiple urls
  636. /*
  637. global $_configuration;
  638. if ($_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) {
  639. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  640. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  641. }*/
  642. //@todo implement visibility
  643. if (isset ($keyword)) {
  644. $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
  645. }
  646. $direction = 'ASC';
  647. if (!in_array($direction, array('ASC','DESC'))) {
  648. $direction = 'ASC';
  649. }
  650. //$column = intval($column);
  651. $from = intval($from);
  652. $number_of_items = intval($number_of_items);
  653. //$sql .= " ORDER BY col$column $direction ";
  654. $sql .= " LIMIT $from,$number_of_items";
  655. $res = Database::query($sql);
  656. if (Database::num_rows($res)> 0) {
  657. while ($row = Database::fetch_array($res,'ASSOC')) {
  658. if (!in_array($row['id'], $return)) {
  659. $return[$row['id']] = $row;
  660. }
  661. }
  662. }
  663. return $return;
  664. }
  665. /**
  666. * Creates new group pictures in various sizes of a user, or deletes user pfotos.
  667. * Note: This method relies on configuration setting from dokeos/main/inc/conf/profile.conf.php
  668. * @param int The group id
  669. * @param string $file The common file name for the newly created pfotos. It will be checked and modified for compatibility with the file system.
  670. * If full name is provided, path component is ignored.
  671. * If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() as the prefered way for deletion.
  672. * @param string $source_file The full system name of the image from which user photos will be created.
  673. * @return string/bool Returns the resulting common file name of created images which usually should be stored in database.
  674. * When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE.
  675. */
  676. public static function update_group_picture($group_id, $file = null, $source_file = null) {
  677. // Validation 1.
  678. if (empty($group_id)) {
  679. return false;
  680. }
  681. $delete = empty($file);
  682. if (empty($source_file)) {
  683. $source_file = $file;
  684. }
  685. // Configuration options about user photos.
  686. require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
  687. // User-reserved directory where photos have to be placed.
  688. $path_info = self::get_group_picture_path_by_id($group_id, 'system', true);
  689. $path = $path_info['dir'];
  690. // If this directory does not exist - we create it.
  691. if (!file_exists($path)) {
  692. @mkdir($path, api_get_permissions_for_new_directories(), true);
  693. }
  694. // The old photos (if any).
  695. $old_file = $path_info['file'];
  696. // Let us delete them.
  697. if (!empty($old_file)) {
  698. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
  699. $prefix = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_';
  700. @rename($path.'small_'.$old_file, $path.$prefix.'small_'.$old_file);
  701. @rename($path.'medium_'.$old_file, $path.$prefix.'medium_'.$old_file);
  702. @rename($path.'big_'.$old_file, $path.$prefix.'big_'.$old_file);
  703. @rename($path.$old_file, $path.$prefix.$old_file);
  704. } else {
  705. @unlink($path.'small_'.$old_file);
  706. @unlink($path.'medium_'.$old_file);
  707. @unlink($path.'big_'.$old_file);
  708. @unlink($path.$old_file);
  709. }
  710. }
  711. // Exit if only deletion has been requested. Return an empty picture name.
  712. if ($delete) {
  713. return '';
  714. }
  715. // Validation 2.
  716. $allowed_types = array('jpg', 'jpeg', 'png', 'gif');
  717. $file = str_replace('\\', '/', $file);
  718. $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file;
  719. $extension = strtolower(substr(strrchr($filename, '.'), 1));
  720. if (!in_array($extension, $allowed_types)) {
  721. return false;
  722. }
  723. // This is the common name for the new photos.
  724. if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) {
  725. $old_extension = strtolower(substr(strrchr($old_file, '.'), 1));
  726. $filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file;
  727. $filename = (substr($filename, -1) == '.') ? $filename.$extension : $filename.'.'.$extension;
  728. } else {
  729. $filename = replace_dangerous_char($filename);
  730. if (PREFIX_IMAGE_FILENAME_WITH_UID) {
  731. $filename = uniqid('').'_'.$filename;
  732. }
  733. // We always prefix user photos with user ids, so on setting
  734. // api_get_setting('split_users_upload_directory') === 'true'
  735. // the correspondent directories to be found successfully.
  736. $filename = $group_id.'_'.$filename;
  737. }
  738. // Storing the new photos in 4 versions with various sizes.
  739. $small = self::resize_picture($source_file, 22);
  740. $medium = self::resize_picture($source_file, 85);
  741. $normal = self::resize_picture($source_file, 200);
  742. $big = new Image($source_file); // This is the original picture.
  743. $ok = $small->send_image($path.'small_'.$filename)
  744. && $medium->send_image($path.'medium_'.$filename)
  745. && $normal->send_image($path.'big_'.$filename)
  746. && $big->send_image($path.$filename);
  747. return $ok ? $filename : false;
  748. }
  749. /**
  750. * Gets the group picture URL or path from group ID (returns an array).
  751. * The return format is a complete path, enabling recovery of the directory
  752. * with dirname() or the file with basename(). This also works for the
  753. * functions dealing with the user's productions, as they are located in
  754. * the same directory.
  755. * @param integer User ID
  756. * @param string Type of path to return (can be 'none', 'system', 'rel', 'web')
  757. * @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)
  758. * @param bool If we want that the function returns the /main/img/unknown.jpg image set it at true
  759. * @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
  760. */
  761. public static function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) {
  762. switch ($type) {
  763. case 'system': // Base: absolute system path.
  764. $base = api_get_path(SYS_CODE_PATH);
  765. break;
  766. case 'rel': // Base: semi-absolute web path (no server base).
  767. $base = api_get_path(REL_CODE_PATH);
  768. break;
  769. case 'web': // Base: absolute web path.
  770. $base = api_get_path(WEB_CODE_PATH);
  771. break;
  772. case 'none':
  773. default: // Base: empty, the result path below will be relative.
  774. $base = '';
  775. }
  776. if (empty($id) || empty($type)) {
  777. return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
  778. }
  779. $id = intval($id);
  780. $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
  781. $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id;
  782. $res = Database::query($sql);
  783. if (!Database::num_rows($res)) {
  784. return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
  785. }
  786. $user = Database::fetch_array($res);
  787. $picture_filename = trim($user['picture_uri']);
  788. if (api_get_setting('split_users_upload_directory') === 'true') {
  789. if (!empty($picture_filename)) {
  790. $dir = $base.'upload/users/groups/'.substr($picture_filename, 0, 1).'/'.$id.'/';
  791. } elseif ($preview) {
  792. $dir = $base.'upload/users/groups/'.substr((string)$id, 0, 1).'/'.$id.'/';
  793. } else {
  794. $dir = $base.'upload/users/groups/'.$id.'/';
  795. }
  796. } else {
  797. $dir = $base.'upload/users/groups/'.$id.'/';
  798. }
  799. if (empty($picture_filename) && $anonymous) {
  800. return array('dir' => $base.'img/', 'file' => 'unknown.jpg');
  801. }
  802. return array('dir' => $dir, 'file' => $picture_filename);
  803. }
  804. /**
  805. * Resize a picture
  806. *
  807. * @param string file picture
  808. * @param int size in pixels
  809. * @return obj image object
  810. */
  811. public static function resize_picture($file, $max_size_for_picture) {
  812. $temp = new Image($file);
  813. $picture_infos = api_getimagesize($file);
  814. if ($picture_infos['width'] > $max_size_for_picture) {
  815. $thumbwidth = $max_size_for_picture;
  816. if (empty($thumbwidth) or $thumbwidth == 0) {
  817. $thumbwidth = $max_size_for_picture;
  818. }
  819. $new_height = round(($thumbwidth / $picture_infos['width']) * $picture_infos['height']);
  820. if ($new_height > $max_size_for_picture)
  821. $new_height = $thumbwidth;
  822. $temp->resize($thumbwidth, $new_height, 0);
  823. }
  824. return $temp;
  825. }
  826. /**
  827. * Gets the current group image
  828. * @param string group id
  829. * @param string picture group name
  830. * @param string height
  831. * @param string picture size it can be small_, medium_ or big_
  832. * @param string style css
  833. * @return array with the file and the style of an image i.e $array['file'] $array['style']
  834. */
  835. public static function get_picture_group($id, $picture_file, $height, $size_picture = GROUP_IMAGE_SIZE_MEDIUM , $style = '') {
  836. $patch_profile = 'upload/users/groups/';
  837. $picture = array();
  838. $picture['style'] = $style;
  839. if ($picture_file == 'unknown.jpg') {
  840. $picture['file'] = api_get_path(WEB_CODE_PATH).'img/'.$picture_file;
  841. return $picture;
  842. }
  843. switch ($size_picture) {
  844. case GROUP_IMAGE_SIZE_ORIGINAL :
  845. $size_picture = '';
  846. break;
  847. case GROUP_IMAGE_SIZE_BIG :
  848. $size_picture = 'big_';
  849. break;
  850. case GROUP_IMAGE_SIZE_MEDIUM :
  851. $size_picture = 'medium_';
  852. break;
  853. case GROUP_IMAGE_SIZE_SMALL :
  854. $size_picture = 'small_';
  855. break;
  856. default:
  857. $size_picture = 'medium_';
  858. }
  859. $image_array_sys = self::get_group_picture_path_by_id($id, 'system', false, true);
  860. $image_array = self::get_group_picture_path_by_id($id, 'web', false, true);
  861. $file = $image_array_sys['dir'].$size_picture.$picture_file;
  862. if (file_exists($file)) {
  863. $picture['file'] = $image_array['dir'].$size_picture.$picture_file;
  864. $picture['style'] = '';
  865. if ($height > 0) {
  866. $dimension = api_getimagesize($picture['file']);
  867. $margin = (($height - $dimension['width']) / 2);
  868. //@ todo the padding-top should not be here
  869. $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension['width'].'px; height:'.$dimension['height'].';" ';
  870. }
  871. } else {
  872. //$file = api_get_path(SYS_CODE_PATH).$patch_profile.$user_id.'/'.$picture_file;
  873. $file = $image_array_sys['dir'].$picture_file;
  874. if (file_exists($file) && !is_dir($file)) {
  875. $picture['file'] = $image_array['dir'].$picture_file;
  876. } else {
  877. $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_group.png';
  878. }
  879. }
  880. return $picture;
  881. }
  882. public static function delete_group_picture($group_id) {
  883. return self::update_group_picture($group_id);
  884. }
  885. public static function is_group_admin($group_id, $user_id = 0) {
  886. if (empty($user_id)) {
  887. $user_id = api_get_user_id();
  888. }
  889. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  890. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN))) {
  891. return true;
  892. } else {
  893. return false;
  894. }
  895. }
  896. public static function is_group_moderator($group_id, $user_id = 0) {
  897. if (empty($user_id)) {
  898. $user_id = api_get_user_id();
  899. }
  900. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  901. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  902. return true;
  903. } else {
  904. return false;
  905. }
  906. }
  907. public static function is_group_member($group_id, $user_id = 0) {
  908. if (empty($user_id)) {
  909. $user_id = api_get_user_id();
  910. }
  911. $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
  912. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_HRM))) {
  913. return true;
  914. } else {
  915. return false;
  916. }
  917. }
  918. /**
  919. * Shows the left column of the group page
  920. * @param int group id
  921. * @param int user id
  922. *
  923. */
  924. public static function show_group_column_information($group_id, $user_id, $show = '') {
  925. global $relation_group_title, $my_group_role;
  926. $html = '';
  927. $group_info = GroupPortalManager::get_group_data($group_id);
  928. //$picture = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,GROUP_IMAGE_SIZE_MEDIUM);
  929. //$big_image = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],'',GROUP_IMAGE_SIZE_BIG);
  930. //$tags = GroupPortalManager::get_group_tags($group_id, true);
  931. //$groups_by_user = GroupPortalManager::get_groups_by_user($user_id, 0);
  932. //my relation with the group is set here
  933. $my_group_role = self::get_user_group_role($user_id, $group_id);
  934. //@todo this must be move to default.css for dev use only
  935. $html .= '<style>
  936. #group_members { width:270px; height:300px; overflow-x:none; overflow-y: auto;}
  937. .group_member_item { width:100px; height:130px; float:left; margin:5px 5px 15px 5px; }
  938. .group_member_picture { display:block;
  939. margin:0;
  940. overflow:hidden; };
  941. </style>';
  942. //Loading group permission
  943. $links = '';
  944. switch ($my_group_role) {
  945. case GROUP_USER_PERMISSION_READER:
  946. // I'm just a reader
  947. $relation_group_title = get_lang('IAmAReader');
  948. $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>';
  949. $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>';
  950. break;
  951. case GROUP_USER_PERMISSION_ADMIN:
  952. $relation_group_title = get_lang('IAmAnAdmin');
  953. $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>';
  954. $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>';
  955. $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>';
  956. $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>';
  957. break;
  958. case GROUP_USER_PERMISSION_PENDING_INVITATION:
  959. // $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>';
  960. break;
  961. case GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER:
  962. $relation_group_title = get_lang('WaitingForAdminResponse');
  963. break;
  964. case GROUP_USER_PERMISSION_MODERATOR:
  965. $relation_group_title = get_lang('IAmAModerator');
  966. //$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>';
  967. //$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>';
  968. //$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>';
  969. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  970. $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>';
  971. }
  972. $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>';
  973. $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>';
  974. break;
  975. case GROUP_USER_PERMISSION_HRM:
  976. $relation_group_title = get_lang('IAmAHRM');
  977. $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>';
  978. $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>';
  979. $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>';
  980. $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>';
  981. $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>';
  982. break;
  983. default:
  984. //$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>';
  985. break;
  986. }
  987. if (!empty($links)) {
  988. $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">';
  989. if (!empty($group_info['description'])) {
  990. $html .= Display::tag('li', Security::remove_XSS($group_info['description'], STUDENT, true), array('class'=>'group_description'));
  991. }
  992. $html .= $links;
  993. $html .= '</ul></div>';
  994. }
  995. return $html;
  996. }
  997. function delete_topic($group_id, $topic_id) {
  998. $table_message = Database::get_main_table(TABLE_MESSAGE);
  999. $topic_id = intval($topic_id);
  1000. $group_id = intval($group_id);
  1001. $sql = "UPDATE $table_message SET msg_status=3 WHERE group_id = $group_id AND (id = '$topic_id' OR parent_id = $topic_id) ";
  1002. Database::query($sql);
  1003. }
  1004. }