group_portal_manager.lib.php 43 KB

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