group_portal_manager.lib.php 46 KB

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