123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113 |
- <?php
- define('GROUP_PERMISSION_OPEN' , '1');
- define('GROUP_PERMISSION_CLOSED', '2');
- define('GROUP_USER_PERMISSION_ADMIN' ,'1');
- define('GROUP_USER_PERMISSION_READER' ,'2');
- define('GROUP_USER_PERMISSION_PENDING_INVITATION' ,'3');
- define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER' ,'4');
- define('GROUP_USER_PERMISSION_MODERATOR' ,'5');
- define('GROUP_USER_PERMISSION_ANONYMOUS' ,'6');
- define('GROUP_USER_PERMISSION_HRM', '7');
- define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
- define('GROUP_IMAGE_SIZE_BIG', 2);
- define('GROUP_IMAGE_SIZE_MEDIUM', 3);
- define('GROUP_IMAGE_SIZE_SMALL', 4);
- define('GROUP_TITLE_LENGTH', 50);
- class GroupPortalManager {
-
- public static function add($name, $description, $url, $visibility, $picture='') {
- $tms = time();
- $table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $sql = "INSERT INTO $table
- SET name = '".Database::escape_string($name)."',
- description = '".Database::escape_string($description)."',
- picture_uri = '".Database::escape_string($picture)."',
- url = '".Database::escape_string($url)."',
- visibility = '".Database::escape_string($visibility)."',
- created_on = FROM_UNIXTIME(".$tms."),
- updated_on = FROM_UNIXTIME(".$tms.")";
- $result = Database::query($sql);
- $return = Database::insert_id();
- return $return;
- }
-
- public static function update($group_id, $name, $description, $url, $visibility, $picture_uri) {
- $group_id = intval($group_id);
- $table = Database::get_main_table(TABLE_MAIN_GROUP);
- $tms = time();
- $sql = "UPDATE $table
- SET name = '".Database::escape_string($name)."',
- description = '".Database::escape_string($description)."',
- picture_uri = '".Database::escape_string($picture_uri)."',
- url = '".Database::escape_string($url)."',
- visibility = '".Database::escape_string($visibility)."',
- updated_on = FROM_UNIXTIME(".$tms.")
- WHERE id = '$group_id'";
- $result = Database::query($sql);
- return $result;
- }
-
- public static function delete($id)
- {
- $id = intval($id);
- $table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $sql= "DELETE FROM $table WHERE id = ".Database::escape_string($id);
- $result = Database::query($sql);
-
- self::delete_users($id);
-
- self::delete_group_picture($id);
- return $result;
- }
-
- public static function get_all_group_data($visibility = GROUP_PERMISSION_OPEN, $from=0, $number_of_items=10)
- {
- $table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $visibility = intval($visibility);
- $user_condition = '';
- $sql = "SELECT name, description, picture_uri FROM $table WHERE visibility = $visibility ";
- $res = Database::query($sql);
- $data = array ();
- while ($item = Database::fetch_array($res)) {
- $data[] = $item;
- }
- return $data;
- }
-
- public static function get_groups_list($without_this_one = NULL ) {
- $where='';
- if ( isset($without_this_one) && (intval($without_this_one) == $without_this_one) ) {
- $where = "WHERE id <> $without_this_one";
- }
- $table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $sql = "SELECT id, name FROM $table $where order by name";
- $res = Database::query($sql);
- $list = array ();
- while ($item = Database::fetch_assoc($res)) {
- $list[$item['id']] = $item['name'];
- }
- return $list;
- }
-
- public static function get_group_data($group_id)
- {
- $table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $group_id = intval($group_id);
- $user_condition = '';
- $sql = "SELECT id, name, description, picture_uri, url, visibility FROM $table WHERE id = $group_id ";
- $res = Database::query($sql);
- $item = array();
- if (Database::num_rows($res)>0) {
- $item = Database::fetch_array($res,'ASSOC');
- }
- return $item;
- }
-
-
- public static function set_parent_group($group_id, $parent_group_id, $relation_type = 1){
- $table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
- $group_id = intval($group_id);
- $parent_group_id = intval($parent_group_id);
- if ($parent_group_id == 0) {
- $sql = "DELETE FROM $table WHERE subgroup_id = $group_id";
- } else {
- $sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
- $res = Database::query($sql);
- if (Database::num_rows($res)==0) {
- $sql = "INSERT INTO $table SET group_id = $parent_group_id, subgroup_id = $group_id, relation_type = $relation_type";
- } else {
- $sql = "UPDATE $table SET group_id = $parent_group_id, relation_type = $relation_type WHERE subgroup_id = $group_id";
- }
- }
- $res = Database::query($sql);
- return($res);
- }
-
- public static function get_parent_group($group_id, $relation_type=1) {
- $table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
- $group_id=intval($group_id);
- $parent_group_id=intval($parent_group_id);
- $sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
- $res = Database::query($sql);
- if (Database::num_rows($res)==0) {
- return 0;
- } else {
- $arr = Database::fetch_assoc($res);
- return $arr['group_id'];
- }
- }
- public static function get_subgroups($root, $level) {
- $t_group = Database::get_main_table(TABLE_MAIN_GROUP);
- $t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
- $select_part = "SELECT ";
- $cond_part='';
- for ($i=1; $i <= $level; $i++) {
- $g_number=$i;
- $rg_number=$i-1;
- if ( $i == $level) {
- $select_part .= "g$i.id as id_$i, g$i.name as name_$i ";
- } else {
- $select_part .="g$i.id as id_$i, g$i.name name_$i, ";
- }
- if ($i == 1) {
- $cond_part .= "FROM $t_group g1 JOIN $t_rel_group rg0 on g1.id = rg0.subgroup_id and rg0.group_id = $root ";
- } else {
- $cond_part .= "LEFT JOIN $t_rel_group rg$rg_number on g$rg_number.id = rg$rg_number.group_id ";
- $cond_part .= "LEFT JOIN $t_group g$g_number on rg$rg_number.subgroup_id = g$g_number.id ";
- }
- }
- $sql = $select_part.' '. $cond_part;
- $res = Database::query($sql);
- $toreturn = array();
- while ($item = Database::fetch_assoc($res)) {
- foreach ($item as $key => $value ){
- if ($key == 'id_1') {
- $toreturn[$value]['name'] = $item['name_1'];
- } else {
- $temp = explode('_',$key);
- $index_key = $temp[1];
- $string_key = $temp[0];
- $previous_key = $string_key.'_'.$index_key-1;
- if ( $string_key == 'id' && isset($item[$key]) ) {
- $toreturn[$item[$previous_key]]['hrms'][$index_key]['name'] = $item['name_'.$index_id];
- }
- }
- }
- }
- return $toreturn;
- }
- public static function get_parent_groups($group_id) {
- $t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
- $max_level = 10;
- $select_part = "SELECT ";
- $cond_part='';
- for ($i=1; $i <= $max_level; $i++) {
- $g_number=$i;
- $rg_number=$i-1;
- if ( $i == $max_level) {
- $select_part .= "rg$rg_number.group_id as id_$rg_number ";
- } else {
- $select_part .="rg$rg_number.group_id as id_$rg_number, ";
- }
- if ($i == 1) {
- $cond_part .= "FROM $t_rel_group rg0 LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id ";
- } else {
- $cond_part .= " LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id ";
- }
- }
- $sql = $select_part.' '. $cond_part . "WHERE rg0.subgroup_id='$group_id'";
- $res = Database::query($sql);
- $temp_arr = Database::fetch_array($res, 'NUM');
- $toreturn = array();
- if (is_array($temp_arr)) {
- foreach ($temp_arr as $elt) {
- if (isset($elt)) {
- $toreturn[] = $elt;
- }
- }
- }
- return $toreturn;
- }
-
- public static function get_group_tags($group_id, $show_tag_links = true)
- {
- $tag = Database :: get_main_table(TABLE_MAIN_TAG);
- $table_group_rel_tag = Database :: get_main_table(TABLE_MAIN_GROUP_REL_TAG);
- $group_id = intval($group_id);
- $user_condition = '';
- $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 ";
- $res = Database::query($sql);
- $tags = array();
- if (Database::num_rows($res)>0) {
- while ($row = Database::fetch_array($res,'ASSOC')) {
- $tags[] = $row;
- }
- }
- if ($show_tag_links) {
- if (is_array($tags) && count($tags)>0) {
- foreach ($tags as $tag) {
- $tag_tmp[] = '<a href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tag['tag'].'">'.$tag['tag'].'</a>';
- }
- if (is_array($tags) && count($tags)>0) {
- $tags= implode(', ',$tag_tmp);
- }
- } else {
- $tags = '';
- }
- }
- return $tags;
- }
-
- public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) {
- $where = '';
- $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
- $user_id = intval($user_id);
- if ($relation_type == 0) {
- $where_relation_condition = '';
- } else {
- $relation_type = intval($relation_type);
- $where_relation_condition = "AND gu.relation_type = $relation_type ";
- }
- $sql = "SELECT g.picture_uri, g.name, g.description, g.id , gu.relation_type
- FROM $tbl_group g
- INNER JOIN $table_group_rel_user gu
- ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition ORDER BY created_on desc ";
- $result=Database::query($sql);
- $array = array();
- if (Database::num_rows($result) > 0) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if ($with_image) {
- $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
- $img = '<img src="'.$picture['file'].'" />';
- $row['picture_uri'] = $img;
- }
- $array[$row['id']] = $row;
- }
- }
- return $array;
- }
-
- public static function get_groups_by_popularity($num = 6, $with_image = true) {
- $where = '';
- $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
- if (empty($num)) {
- $num = 6;
- } else {
- $num = intval($num);
- }
-
- $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
- $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
- FROM $tbl_group g
- INNER JOIN $table_group_rel_user gu
- ON gu.group_id = g.id $where_relation_condition GROUP BY g.id ORDER BY count DESC LIMIT $num";
- $result=Database::query($sql);
- $array = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if ($with_image) {
- $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
- $img = '<img src="'.$picture['file'].'" />';
- $row['picture_uri'] = $img;
- }
- if (empty($row['id'])) {
- continue;
- }
- $array[$row['id']] = $row;
- }
- return $array;
- }
-
- public static function get_groups_by_age($num = 6, $with_image = true) {
- $where = '';
- $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
- if (empty($num)) {
- $num = 6;
- } else {
- $num = intval($num);
- }
- $where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
- $sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
- FROM $tbl_group g INNER JOIN $table_group_rel_user gu ON gu.group_id = g.id
- $where_relation_condition
- ORDER BY created_on desc LIMIT $num ";
-
- $result=Database::query($sql);
- $array = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if ($with_image) {
- $picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
- $img = '<img src="'.$picture['file'].'" />';
- $row['picture_uri'] = $img;
- }
- if (empty($row['id'])) {
- continue;
- }
- $array[$row['id']] = $row;
- }
- return $array;
- }
-
- 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)) {
- $where = '';
- $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $group_id = intval($group_id);
-
- if (empty($group_id)){
- return array();
- }
- $limit_text = '';
- if (isset($from) && isset($limit)) {
- $from = intval($from);
- $limit = intval($limit);
- $limit_text = "LIMIT $from, $limit";
- }
- if (count($relation_type) == 0) {
- $where_relation_condition = '';
- } else {
- $new_relation_type = array();
- foreach($relation_type as $rel) {
- $rel = intval($rel);
- $new_relation_type[] ="'$rel'";
- }
- $relation_type = implode(',', $new_relation_type);
- if (!empty($relation_type))
- $where_relation_condition = "AND gu.relation_type IN ($relation_type) ";
- }
- $sql = "SELECT picture_uri as image, u.user_id, u.firstname, u.lastname, relation_type
- FROM $tbl_user u INNER JOIN $table_group_rel_user gu
- ON (gu.user_id = u.user_id)
- WHERE gu.group_id= $group_id $where_relation_condition
- ORDER BY relation_type, firstname $limit_text";
- $result = Database::query($sql);
- $array = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if ($with_image) {
- $image_path = UserManager::get_user_picture_path_by_id($row['user_id'], 'web', false, true);
- $picture = UserManager::get_picture_user($row['user_id'], $image_path['file'], $image_conf['height'], $image_conf['size']);
- $row['image'] = '<img src="'.$picture['file'].'" '.$picture['style'].' />';
- }
- $array[$row['user_id']] = $row;
- }
- return $array;
- }
-
- public static function get_all_users_by_group($group_id)
- {
- $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $group_id = intval($group_id);
- if (empty($group_id)){
- return array();
- }
- $sql="SELECT u.user_id, u.firstname, u.lastname, relation_type FROM $tbl_user u
- INNER JOIN $table_group_rel_user gu
- ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id ORDER BY relation_type, firstname";
- $result=Database::query($sql);
- $array = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $array[$row['user_id']] = $row;
- }
- return $array;
- }
-
- public static function get_user_group_role($user_id, $group_id)
- {
- $table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $return_value = 0;
- if (!empty($user_id) && !empty($group_id)) {
- $sql = "SELECT relation_type FROM $table_group_rel_user WHERE group_id = ".intval($group_id)." AND user_id = ".intval($user_id)." ";
- $result = Database::query($sql);
- if (Database::num_rows($result)>0) {
- $row = Database::fetch_array($result,'ASSOC');
- $return_value = $row['relation_type'];
- }
- }
- return $return_value;
- }
-
- public static function add_user_to_group($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER) {
- $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- if (!empty($user_id) && !empty($group_id)) {
- $role = self::get_user_group_role($user_id,$group_id);
- if ($role == 0) {
- $sql = "INSERT INTO $table_url_rel_group
- SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
- $result = Database::query($sql);
- } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
-
- self::update_user_role($user_id, $group_id, GROUP_USER_PERMISSION_READER);
- }
- }
- return $result;
- }
-
- public static function add_users_to_groups($user_list, $group_list, $relation_type = GROUP_USER_PERMISSION_READER) {
- $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $result_array = array();
- $relation_type = intval($relation_type);
- if (is_array($user_list) && is_array($group_list)) {
- foreach ($group_list as $group_id) {
- foreach ($user_list as $user_id) {
- $role = self::get_user_group_role($user_id,$group_id);
- if ($role == 0) {
- $sql = "INSERT INTO $table_url_rel_group
- SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type);
- $result = Database::query($sql);
- if ($result)
- $result_array[$group_id][$user_id]=1;
- else
- $result_array[$group_id][$user_id]=0;
- }
- }
- }
- }
- return $result_array;
- }
-
- public static function delete_users($group_id,$relation_type='')
- {
- $table_ = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $condition_relation = "";
- if (!empty($relation_type)) {
- $relation_type = intval($relation_type);
- $condition_relation = " AND relation_type = '$relation_type'";
- }
- $sql = "DELETE FROM $table_ WHERE group_id = ".intval($group_id).$condition_relation;
- $result = Database::query($sql);
- return $result;
- }
-
- public static function delete_user_rel_group($user_id, $group_id) {
- $table = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $sql= "DELETE FROM $table WHERE user_id = ".intval($user_id)." AND group_id=".intval($group_id)." ";
- $result = Database::query($sql);
- return $result;
- }
-
- public static function update_user_role($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER)
- {
- $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $group_id = intval($group_id);
- $user_id = intval($user_id);
- $sql = "UPDATE $table_group_rel_user
- SET relation_type = ".intval($relation_type)." WHERE user_id = $user_id AND group_id = $group_id" ;
- $result = Database::query($sql);
- }
- public static function get_group_admin_list($user_id, $group_id)
- {
- $table_group_rel_user = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
- $group_id = intval($group_id);
- $user_id = intval($user_id);
- $sql = "SELECT user_id FROM $table_group_rel_user WHERE
- relation_type = ".GROUP_USER_PERMISSION_ADMIN." AND user_id = $user_id AND group_id = $group_id" ;
- $result = Database::query($sql);
- }
- public static function get_all_group_tags($tag, $from=0, $number_of_items=10) {
-
- $group_table = Database::get_main_table(TABLE_MAIN_GROUP);
- $table_tag = Database::get_main_table(TABLE_MAIN_TAG);
- $table_group_tag_values = Database::get_main_table(TABLE_MAIN_GROUP_REL_TAG);
-
- $field_id = 5;
- $tag = Database::escape_string($tag);
- $from = intval($from);
- $number_of_items = intval($number_of_items);
-
- $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)
- INNER JOIN $group_table g ON(tv.group_id =g.id)
- WHERE tag LIKE '$tag%' AND field_id= $field_id ORDER BY tag";
- $sql .= " LIMIT $from,$number_of_items";
- $result = Database::query($sql);
- $return = array();
- if (Database::num_rows($result)> 0) {
- while ($row = Database::fetch_array($result,'ASSOC')) {
- $return[$row['id']] = $row;
- }
- }
- $keyword = $tag;
- $sql = "SELECT g.id, g.name, g.description, g.url, g.picture_uri FROM $group_table g";
-
-
-
- if (isset ($keyword)) {
- $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
- }
- $direction = 'ASC';
- if (!in_array($direction, array('ASC','DESC'))) {
- $direction = 'ASC';
- }
-
- $from = intval($from);
- $number_of_items = intval($number_of_items);
-
- $sql .= " LIMIT $from,$number_of_items";
- $res = Database::query($sql);
- if (Database::num_rows($res)> 0) {
- while ($row = Database::fetch_array($res,'ASSOC')) {
- if (!in_array($row['id'], $return)) {
- $return[$row['id']] = $row;
- }
- }
- }
- return $return;
- }
-
- public static function update_group_picture($group_id, $file = null, $source_file = null) {
-
- if (empty($group_id)) {
- return false;
- }
- $delete = empty($file);
- if (empty($source_file)) {
- $source_file = $file;
- }
-
- require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
-
- $path_info = self::get_group_picture_path_by_id($group_id, 'system', true);
- $path = $path_info['dir'];
-
- if (!file_exists($path)) {
- @mkdir($path, api_get_permissions_for_new_directories(), true);
- }
-
- $old_file = $path_info['file'];
-
- if (!empty($old_file)) {
- if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
- $prefix = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_';
- @rename($path.'small_'.$old_file, $path.$prefix.'small_'.$old_file);
- @rename($path.'medium_'.$old_file, $path.$prefix.'medium_'.$old_file);
- @rename($path.'big_'.$old_file, $path.$prefix.'big_'.$old_file);
- @rename($path.$old_file, $path.$prefix.$old_file);
- } else {
- @unlink($path.'small_'.$old_file);
- @unlink($path.'medium_'.$old_file);
- @unlink($path.'big_'.$old_file);
- @unlink($path.$old_file);
- }
- }
-
- if ($delete) {
- return '';
- }
-
- $allowed_types = array('jpg', 'jpeg', 'png', 'gif');
- $file = str_replace('\\', '/', $file);
- $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file;
- $extension = strtolower(substr(strrchr($filename, '.'), 1));
- if (!in_array($extension, $allowed_types)) {
- return false;
- }
-
- if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) {
- $old_extension = strtolower(substr(strrchr($old_file, '.'), 1));
- $filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file;
- $filename = (substr($filename, -1) == '.') ? $filename.$extension : $filename.'.'.$extension;
- } else {
- $filename = replace_dangerous_char($filename);
- if (PREFIX_IMAGE_FILENAME_WITH_UID) {
- $filename = uniqid('').'_'.$filename;
- }
-
-
-
- $filename = $group_id.'_'.$filename;
- }
-
- $small = self::resize_picture($source_file, 22);
- $medium = self::resize_picture($source_file, 85);
- $normal = self::resize_picture($source_file, 200);
- $big = new Image($source_file);
- $ok = false;
- $ok = $small->send_image($path.'small_'.$filename)
- && $medium->send_image($path.'medium_'.$filename)
- && $normal->send_image($path.'big_'.$filename)
- && $big->send_image($path.$filename);
- return $ok ? $filename : false;
- }
-
- public static function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) {
- switch ($type) {
- case 'system':
- $base = api_get_path(SYS_CODE_PATH);
- break;
- case 'rel':
- $base = api_get_path(REL_CODE_PATH);
- break;
- case 'web':
- $base = api_get_path(WEB_CODE_PATH);
- break;
- case 'none':
- default:
- $base = '';
- }
- if (empty($id) || empty($type)) {
- return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
- }
- $id = intval($id);
- $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
- $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id;
- $res = Database::query($sql);
- if (!Database::num_rows($res)) {
- return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => '');
- }
- $user = Database::fetch_array($res);
- $picture_filename = trim($user['picture_uri']);
- if (api_get_setting('split_users_upload_directory') === 'true') {
- if (!empty($picture_filename)) {
- $dir = $base.'upload/users/groups/'.substr($picture_filename, 0, 1).'/'.$id.'/';
- } elseif ($preview) {
- $dir = $base.'upload/users/groups/'.substr((string)$id, 0, 1).'/'.$id.'/';
- } else {
- $dir = $base.'upload/users/groups/'.$id.'/';
- }
- } else {
- $dir = $base.'upload/users/groups/'.$id.'/';
- }
- if (empty($picture_filename) && $anonymous) {
- return array('dir' => $base.'img/', 'file' => 'unknown.jpg');
- }
- return array('dir' => $dir, 'file' => $picture_filename);
- }
-
- public static function resize_picture($file, $max_size_for_picture) {
- $temp = new image($file);
- $picture_infos = api_getimagesize($file);
- if ($picture_infos['width'] > $max_size_for_picture) {
- $thumbwidth = $max_size_for_picture;
- if (empty($thumbwidth) or $thumbwidth == 0) {
- $thumbwidth = $max_size_for_picture;
- }
- $new_height = round(($thumbwidth / $picture_infos['width']) * $picture_infos['height']);
- if ($new_height > $max_size_for_picture)
- $new_height = $thumbwidth;
- $temp->resize($thumbwidth, $new_height, 0);
- }
- return $temp;
- }
-
- public static function get_picture_group($id, $picture_file, $height, $size_picture = GROUP_IMAGE_SIZE_MEDIUM , $style = '') {
- $patch_profile = 'upload/users/groups/';
- $picture = array();
- $picture['style'] = $style;
- if ($picture_file == 'unknown.jpg') {
- $picture['file'] = api_get_path(WEB_CODE_PATH).'img/'.$picture_file;
- return $picture;
- }
- switch ($size_picture) {
- case GROUP_IMAGE_SIZE_ORIGINAL :
- $size_picture = '';
- break;
- case GROUP_IMAGE_SIZE_BIG :
- $size_picture = 'big_';
- break;
- case GROUP_IMAGE_SIZE_MEDIUM :
- $size_picture = 'medium_';
- break;
- case GROUP_IMAGE_SIZE_SMALL :
- $size_picture = 'small_';
- break;
- default:
- $size_picture = 'medium_';
- }
- $image_array_sys = self::get_group_picture_path_by_id($id, 'system', false, true);
- $image_array = self::get_group_picture_path_by_id($id, 'web', false, true);
- $file = $image_array_sys['dir'].$size_picture.$picture_file;
- if (file_exists($file)) {
- $picture['file'] = $image_array['dir'].$size_picture.$picture_file;
- $picture['style'] = '';
- if ($height > 0) {
- $dimension = api_getimagesize($picture['file']);
- $margin = (($height - $dimension['width']) / 2);
-
- $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension['width'].'px; height:'.$dimension['height'].';" ';
- }
- } else {
-
- $file = $image_array_sys['dir'].$picture_file;
- if (file_exists($file) && !is_dir($file)) {
- $picture['file'] = $image_array['dir'].$picture_file;
- } else {
- $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_group.png';
- }
- }
- return $picture;
- }
- public static function delete_group_picture($group_id) {
- return self::update_group_picture($group_id);
- }
- public static function is_group_admin($group_id, $user_id = 0) {
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
- if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN))) {
- return true;
- } else {
- return false;
- }
- }
- public static function is_group_moderator($group_id, $user_id = 0) {
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
- if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
- return true;
- } else {
- return false;
- }
- }
- public static function is_group_member($group_id, $user_id = 0) {
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id);
- if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_HRM))) {
- return true;
- } else {
- return false;
- }
- }
-
- public static function show_group_column_information($group_id, $user_id, $show = '') {
- global $relation_group_title, $my_group_role;
- $html = '';
- $group_info = GroupPortalManager::get_group_data($group_id);
- $picture = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,GROUP_IMAGE_SIZE_MEDIUM);
- $big_image = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],'',GROUP_IMAGE_SIZE_BIG);
- $tags = GroupPortalManager::get_group_tags($group_id, true);
-
- $groups_by_user = GroupPortalManager::get_groups_by_user($user_id, 0);
-
- $my_group_role = self::get_user_group_role($user_id, $group_id);
-
- $html .= '<style>
- #group_members { width:270px; height:300px; overflow-x:none; overflow-y: auto;}
- .group_member_item { width:100px; height:130px; float:left; margin:5px 5px 15px 5px; }
- .group_member_picture { display:block;
- margin:0;
- overflow:hidden; };
- </style>';
-
-
- $links = '';
- switch ($my_group_role) {
- case GROUP_USER_PERMISSION_READER:
-
- $relation_group_title = get_lang('IAmAReader');
- $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>';
- $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>';
- break;
- case GROUP_USER_PERMISSION_ADMIN:
- $relation_group_title = get_lang('IAmAnAdmin');
- $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>';
- $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>';
- $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>';
- break;
- case GROUP_USER_PERMISSION_PENDING_INVITATION:
- break;
- case GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER:
- $relation_group_title = get_lang('WaitingForAdminResponse');
- break;
- case GROUP_USER_PERMISSION_MODERATOR:
- $relation_group_title = get_lang('IAmAModerator');
-
-
-
- if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
- $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>';
- }
- $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>';
- break;
- case GROUP_USER_PERMISSION_HRM:
- $relation_group_title = get_lang('IAmAHRM');
- $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="ajax" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('compose_message.png', get_lang('NewTopic'), array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('NewTopic').'</span></a></li>';
- $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>';
- $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>';
- $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>';
- $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>';
- break;
- default:
-
- break;
- }
- if (!empty($links)) {
- $html .= '<ul class="social-menu-groups">';
- if (!empty($group_info['description'])) {
- $html .= Display::tag('li', Security::remove_XSS($group_info['description'], STUDENT, true), array('class'=>'group_description'));
- }
- $html .= $links;
- $html .= '</ul>';
- }
- return $html;
- }
-
- function delete_topic($group_id, $topic_id) {
- $table_message = Database::get_main_table(TABLE_MESSAGE);
- $topic_id = intval($topic_id);
- $group_id = intval($group_id);
- $sql = "UPDATE $table_message SET msg_status=3 WHERE group_id = $group_id AND (id = '$topic_id' OR parent_id = $topic_id) ";
- Database::query($sql);
- }
- }
|