diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 5e8d599a1e..b066c25c74 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -285,7 +285,7 @@ class MessageManager $sender_info = api_get_user_info($user_sender_id); if (empty($group_id)) { - $notification->save_notification(NOTIFICATION_TYPE_MESSAGE, array($receiver_user_id), $subject, $content, $sender_info); + $notification->save_notification(Notification::NOTIFICATION_TYPE_MESSAGE, array($receiver_user_id), $subject, $content, $sender_info); } else { $group_info = GroupPortalManager::get_group_data($group_id); $group_info['topic_id'] = $topic_id; @@ -301,7 +301,7 @@ class MessageManager $new_user_list[] = $user_data['user_id']; } $group_info = array('group_info' => $group_info, 'user_info' => $sender_info); - $notification->save_notification(NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info); + $notification->save_notification(Notification::NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info); } return $inbox_last_id; } diff --git a/main/inc/lib/notification.lib.php b/main/inc/lib/notification.lib.php index c2f8af09fb..c1ca3b00e6 100644 --- a/main/inc/lib/notification.lib.php +++ b/main/inc/lib/notification.lib.php @@ -1,93 +1,86 @@ table = Database::get_main_table(TABLE_NOTIFICATION); - - $this->admin_email = api_get_setting('noreply_email_address'); - $this->admin_name = api_get_setting('siteName'); + public $type; + public $admin_name; + public $admin_email; + //mail_notify_message ("At once", "Daily", "No") + const NOTIFY_MESSAGE_AT_ONCE = 1; + const NOTIFY_MESSAGE_DAILY = 8; + const NOTIFY_MESSAGE_WEEKLY = 12; + const NOTIFY_MESSAGE_NO = 0; + + //mail_notify_invitation ("At once", "Daily", "No") + const NOTIFY_INVITATION_AT_ONCE = 1; + const NOTIFY_INVITATION_DAILY = 8; + const NOTIFY_INVITATION_WEEKLY = 12; + const NOTIFY_INVITATION_NO = 0; + + // mail_notify_group_message ("At once", "Daily", "No") + const NOTIFY_GROUP_AT_ONCE = 1; + const NOTIFY_GROUP_DAILY = 8; + const NOTIFY_GROUP_WEEKLY = 12; + const NOTIFY_GROUP_NO = 0; + const NOTIFICATION_TYPE_MESSAGE = 1; + const NOTIFICATION_TYPE_INVITATION = 2; + const NOTIFICATION_TYPE_GROUP = 3; + + public function __construct() + { + $this->table = Database::get_main_table(TABLE_NOTIFICATION); + + $this->admin_email = api_get_setting('noreply_email_address'); + $this->admin_name = api_get_setting('siteName'); // If no-reply email doesn't exist use the admin email if (empty($this->admin_email)) { $this->admin_email = api_get_setting('emailAdministrator'); - $this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); + $this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); } - } + } /** * Send the notifications * @param int notification frecuency */ - public function send($frec = NOTIFY_MESSAGE_DAILY) { - $notifications = $this->find('all',array('where'=>array('sent_at IS NULL AND send_freq = ?'=>$frec))); - + public function send($frec = 8) + { + $notifications = $this->find('all', array('where' => array('sent_at IS NULL AND send_freq = ?' => $frec))); if (!empty($notifications)) { foreach ($notifications as $item_to_send) { - //Sending email - api_mail_html($item_to_send['dest_mail'], - $item_to_send['dest_mail'], - Security::filter_terms($item_to_send['title']), - Security::filter_terms($item_to_send['content']), - $this->admin_name, - $this->admin_email - ); - if ($this->debug) { error_log('Sending message to: '.$item_to_send['dest_mail']); } + api_mail_html($item_to_send['dest_mail'], $item_to_send['dest_mail'], Security::filter_terms($item_to_send['title']), Security::filter_terms($item_to_send['content']), $this->admin_name, $this->admin_email); + if ($this->debug) { + error_log('Sending message to: '.$item_to_send['dest_mail']); + } //Updating $item_to_send['sent_at'] = api_get_utc_datetime(); $this->update($item_to_send); - if ($this->debug) { error_log('Updating record : '.print_r($item_to_send,1)); } + if ($this->debug) { + error_log('Updating record : '.print_r($item_to_send, 1)); + } } } } @@ -100,26 +93,27 @@ class Notification extends Model { * @param string content of the message * @param array result of api_get_user_info() or GroupPortalManager:get_group_data() */ - public function save_notification($type, $user_list, $title, $content, $sender_info = array()) { + public function save_notification($type, $user_list, $title, $content, $sender_info = array()) + { $this->type = intval($type); - $content = $this->format_content($content, $sender_info); + $content = $this->format_content($content, $sender_info); $setting_to_check = ''; - $avoid_my_self = false; + $avoid_my_self = false; switch ($this->type) { - case NOTIFICATION_TYPE_MESSAGE; + case self::NOTIFICATION_TYPE_MESSAGE; $setting_to_check = 'mail_notify_message'; - $default_status = NOTIFY_MESSAGE_AT_ONCE; + $default_status = self::NOTIFY_MESSAGE_AT_ONCE; break; - case NOTIFICATION_TYPE_INVITATION; + case self::NOTIFICATION_TYPE_INVITATION; $setting_to_check = 'mail_notify_invitation'; - $default_status = NOTIFY_INVITATION_AT_ONCE; + $default_status = self::NOTIFY_INVITATION_AT_ONCE; break; - case NOTIFICATION_TYPE_GROUP; + case self::NOTIFICATION_TYPE_GROUP; $setting_to_check = 'mail_notify_group_message'; - $default_status = NOTIFY_GROUP_AT_ONCE; - $avoid_my_self = true; + $default_status = self::NOTIFY_GROUP_AT_ONCE; + $avoid_my_self = true; break; } @@ -146,14 +140,14 @@ class Notification extends Model { switch ($user_setting) { //No notifications - case NOTIFY_MESSAGE_NO: - case NOTIFY_INVITATION_NO: - case NOTIFY_GROUP_NO: + case self::NOTIFY_MESSAGE_NO: + case self::NOTIFY_INVITATION_NO: + case self::NOTIFY_GROUP_NO: break; //Send notification right now! - case NOTIFY_MESSAGE_AT_ONCE: - case NOTIFY_INVITATION_AT_ONCE: - case NOTIFY_GROUP_AT_ONCE: + case self::NOTIFY_MESSAGE_AT_ONCE: + case self::NOTIFY_INVITATION_AT_ONCE: + case self::NOTIFY_GROUP_AT_ONCE: if (!empty($user_info['mail'])) { $name = api_get_person_name($user_info['firstname'], $user_info['lastname']); if (!empty($sender_info['complete_name']) && !empty($sender_info['email'])) { @@ -165,16 +159,16 @@ class Notification extends Model { api_mail_html($name, $user_info['mail'], Security::filter_terms($title), Security::filter_terms($content), $this->admin_name, $this->admin_email); } } - $params['sent_at'] = api_get_utc_datetime(); - //Saving the notification to be sent some day + $params['sent_at'] = api_get_utc_datetime(); + //Saving the notification to be sent some day default: - $params['dest_user_id'] = $user_id; - $params['dest_mail'] = $user_info['mail']; - $params['title'] = $title; - $params['content'] = cut($content, $this->max_content_length); - $params['send_freq'] = $user_setting; - $this->save($params); - break; + $params['dest_user_id'] = $user_id; + $params['dest_mail'] = $user_info['mail']; + $params['title'] = $title; + $params['content'] = cut($content, $this->max_content_length); + $params['send_freq'] = $user_setting; + $this->save($params); + break; } } } @@ -185,11 +179,12 @@ class Notification extends Model { * @param string the content * @param array result of api_get_user_info() or GroupPortalManager:get_group_data() * */ - public function format_content($content, $sender_info) { + public function format_content($content, $sender_info) + { $new_message_text = $link_to_new_message = ''; - switch($this->type) { - case NOTIFICATION_TYPE_MESSAGE: + switch ($this->type) { + case self::NOTIFICATION_TYPE_MESSAGE: if (!empty($sender_info)) { $sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); //$sender_mail = $sender_info['email'] ; @@ -197,7 +192,7 @@ class Notification extends Model { } $link_to_new_message = Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'messages/inbox.php'); break; - case NOTIFICATION_TYPE_INVITATION: + case self::NOTIFICATION_TYPE_INVITATION: if (!empty($sender_info)) { $sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); //$sender_mail = $sender_info['email'] ; @@ -205,15 +200,14 @@ class Notification extends Model { } $link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php'); break; - case NOTIFICATION_TYPE_GROUP: - $topic_page = intval($_REQUEST['topics_page_nr']); + case self::NOTIFICATION_TYPE_GROUP: + $topic_page = intval($_REQUEST['topics_page_nr']); if (!empty($sender_info)) { $sender_name = $sender_info['group_info']['name']; - $new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name); + $new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name); $sender_name = api_get_person_name($sender_info['user_info']['firstname'], $sender_info['user_info']['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); - $sender_name = Display::url($sender_name , api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']); - $new_message_text .= '
'.get_lang('User').': '.$sender_name; - + $sender_name = Display::url($sender_name, api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']); + $new_message_text .= '
'.get_lang('User').': '.$sender_name; } $group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page; $link_to_new_message = Display::url(get_lang('SeeMessage'), $group_url); @@ -232,8 +226,8 @@ class Notification extends Model { } // You have received this message because you are subscribed text - $content = $content.'

'. - sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).''; + $content = $content.'

'. + sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).''; return $content; } } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index bd7f2aef17..607163f43b 100644 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -31,7 +31,7 @@ class SocialManager extends UserManager { /** * Allow to see contacts list - * @author isaac flores paz + * @author isaac flores paz * @return array */ public static function show_list_type_friends () { @@ -50,14 +50,14 @@ class SocialManager extends UserManager { return $friend_relation_list; } } - + /** * Get relation type contact by name * @param string names of the kind of relation * @return int - * @author isaac flores paz + * @author isaac flores paz */ - public static function get_relation_type_by_name ($relation_type_name) { + public static function get_relation_type_by_name ($relation_type_name) { $list_type_friend = self::show_list_type_friends(); foreach ($list_type_friend as $value_type_friend) { if (strtolower($value_type_friend['title'])==$relation_type_name) { @@ -65,13 +65,13 @@ class SocialManager extends UserManager { } } } - + /** * Get the kind of relation between contacts * @param int user id * @param int user friend id * @param string - * @author isaac flores paz + * @author isaac flores paz */ public static function get_relation_between_contacts ($user_id,$user_friend) { $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); @@ -95,7 +95,7 @@ class SocialManager extends UserManager { * @param bool true will load firstname, lastname, and image name * @return array * @author Julio Montoya Cleaning code, function renamed, $load_extra_info option added - * @author isaac flores paz + * @author isaac flores paz */ public static function get_friends($user_id, $id_group = null, $search_name = null, $load_extra_info = true) { $list_ids_friends=array(); @@ -131,9 +131,9 @@ class SocialManager extends UserManager { * @param int group id * @param string name to search * @param array - * @author isaac flores paz + * @author isaac flores paz */ - public static function get_list_path_web_by_user_id ($user_id,$id_group=null,$search_name=null) { + public static function get_list_path_web_by_user_id ($user_id,$id_group=null,$search_name=null) { $combine_friend = array(); $list_ids = self::get_friends($user_id,$id_group,$search_name); if (is_array($list_ids)) { @@ -152,7 +152,7 @@ class SocialManager extends UserManager { * @param int user id * @return array */ - public static function get_list_web_path_user_invitation_by_user_id ($user_id) { + public static function get_list_web_path_user_invitation_by_user_id ($user_id) { $list_ids = self::get_list_invitation_of_friends_by_user_id((int)$user_id); $list_path_image_friend = array(); foreach ($list_ids as $values_ids) { @@ -175,30 +175,30 @@ class SocialManager extends UserManager { $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); $user_id = intval($user_id); $friend_id = intval($friend_id); - + //Just in case we replace the and \n and \n\r while saving in the DB - $message_content = str_replace(array("\n", "\n\r"), '
', $message_content); - + $message_content = str_replace(array("\n", "\n\r"), '
', $message_content); + $clean_message_title = Database::escape_string($message_title); $clean_message_content = Database::escape_string($message_content); - + $now = api_get_utc_datetime(); - + $sql_exist='SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status IN(5,6,7);'; $res_exist = Database::query($sql_exist); $row_exist = Database::fetch_array($res_exist,'ASSOC'); - + if ($row_exist['count']==0) { - - $sql=' INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content) + + $sql=' INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content) VALUES('.$user_id.','.$friend_id.','.MESSAGE_STATUS_INVITATION_PENDING.',"'.$now.'","'.$clean_message_title.'","'.$clean_message_content.'") '; - Database::query($sql); - + Database::query($sql); + $sender_info = api_get_user_info($user_id); - $notification = new Notification(); - $notification->save_notification(NOTIFICATION_TYPE_INVITATION, array($friend_id), $message_title, $message_content, $sender_info); - + $notification = new Notification(); + $notification->save_notification(Notification::NOTIFICATION_TYPE_INVITATION, array($friend_id), $message_title, $message_content, $sender_info); + return true; } else { //invitation already exist @@ -216,7 +216,7 @@ class SocialManager extends UserManager { } /** * Get number messages of the inbox - * @author isaac flores paz + * @author isaac flores paz * @param int user receiver id * @return int */ @@ -230,7 +230,7 @@ class SocialManager extends UserManager { /** * Get invitation list received by user - * @author isaac flores paz + * @author isaac flores paz * @param int user id * @return array() */ @@ -267,7 +267,7 @@ class SocialManager extends UserManager { * Accepts invitation * @param int user sender id * @param int user receiver id - * @author isaac flores paz + * @author isaac flores paz * @author Julio Montoya Cleaning code */ public static function invitation_accepted ($user_send_id,$user_receiver_id) { @@ -279,7 +279,7 @@ class SocialManager extends UserManager { * Denies invitation * @param int user sender id * @param int user receiver id - * @author isaac flores paz + * @author isaac flores paz * @author Julio Montoya Cleaning code */ public static function invitation_denied ($user_send_id,$user_receiver_id) { @@ -291,7 +291,7 @@ class SocialManager extends UserManager { } /** * allow attach to group - * @author isaac flores paz + * @author isaac flores paz * @param int user to qualify * @param int kind of rating * @return void() @@ -311,15 +311,15 @@ class SocialManager extends UserManager { */ public static function send_invitation_friend_user($userfriend_id, $subject_message = '', $content_message = '') { global $charset; - + $user_info = array(); $user_info = api_get_user_info($userfriend_id); $succes = get_lang('MessageSentTo'); $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); - + if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) { - $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message); - + $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message); + if ($send_message) { echo Display::display_confirmation_message($succes,true); } else { @@ -327,7 +327,7 @@ class SocialManager extends UserManager { } return false; } elseif (isset($userfriend_id) && !isset($subject_message)) { - $count_is_true = false; + $count_is_true = false; if (isset($userfriend_id) && $userfriend_id>0) { $message_title = get_lang('Invitation'); $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message); @@ -394,13 +394,13 @@ class SocialManager extends UserManager { // Table definitions $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); - + $course_code = $my_course['code']; $course_visual_code = $my_course['course_info']['official_code']; $course_title = $my_course['course_info']['title']; - + $course_info = Database :: get_course_info($course_code); - + $course_id = $course_info['real_id']; $course_access_settings = CourseManager :: get_access_settings($course_code); @@ -420,7 +420,7 @@ class SocialManager extends UserManager { return; //do not display this course entry } } - + $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')); //display course entry @@ -506,7 +506,7 @@ class SocialManager extends UserManager { } $active = ($date_start <= $now && $date_end >= $now)?true:false; } - } + } $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active); } else { @@ -528,18 +528,18 @@ class SocialManager extends UserManager { public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false) { if (empty($user_id)) { $user_id = api_get_user_id(); - } + } $user_info = api_get_user_info($user_id, true); - + $current_user_id = api_get_user_id(); $current_user_info = api_get_user_info($current_user_id, true); - + if ($current_user_id == $user_id) { $user_friend_relation = null; } else { $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id); } - + $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); //$show_messages = array('messages', 'messages_inbox', 'messages_outbox', 'messages_compose'); @@ -552,30 +552,30 @@ class SocialManager extends UserManager { $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) :''); - + $html = ''; } } return $html; - } - + } + /** * Displays the information of an individual user * @param int $user_id @@ -819,14 +819,14 @@ class SocialManager extends UserManager { $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id; $result = Database::query($sql); if (Database::num_rows($result) == 1) { - $user_object = Database::fetch_object($result); + $user_object = Database::fetch_object($result); $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? ' ('.get_lang('Me').')' : ''); $status = get_status_from_code($user_object->status); - + $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')); - Display::display_header($alt, null, $alt); - + Display::display_header($alt, null, $alt); + echo '
'; if (strlen(trim($user_object->picture_uri)) > 0) { $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system'); @@ -835,9 +835,9 @@ class SocialManager extends UserManager { $webdir = $webdir_array['dir']; $fullurl = $webdir.$user_object->picture_uri; $system_image_path = $sysdir.$user_object->picture_uri; - list($width, $height, $type, $attr) = @getimagesize($system_image_path); + list($width, $height, $type, $attr) = @getimagesize($system_image_path); $height += 30; - $width += 30; + $width += 30; // get the path,width and height from original picture $big_image = $webdir.'big_'.$user_object->picture_uri; $big_image_size = api_getimagesize($big_image); @@ -847,18 +847,18 @@ class SocialManager extends UserManager { //echo ''; echo ''.$alt.''; } else { - echo Display::return_icon('unknown.jpg', get_lang('Unknown')); - } + echo Display::return_icon('unknown.jpg', get_lang('Unknown')); + } if (!empty($status)) { echo '
'.$status.'
'; } echo '
'; - + if (api_get_setting('show_email_addresses') == 'true') { echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'
'; } - + if ($user_object->competences) { echo Display::page_subheader(get_lang('MyCompetences')); echo '

'.$user_object->competences.'

'; @@ -876,7 +876,7 @@ class SocialManager extends UserManager { echo Display::page_subheader(get_lang('MyPersonalOpenArea')); echo '

'.$user_object->openarea.'

'; } - + } else { Display::display_header(get_lang('UsersOnLineList')); echo '
'; @@ -884,7 +884,7 @@ class SocialManager extends UserManager { echo '
'; } } - + /** * Display productions in whoisonline * @param int $user_id User id @@ -934,7 +934,7 @@ class SocialManager extends UserManager { echo ''; } } - + public static function social_wrapper_div($content, $span_count) { $span_count = intval($span_count); $html = '
'; @@ -942,9 +942,9 @@ class SocialManager extends UserManager { $html .= $content; $html .= '
'; return $html; - + } - + /** * Dummy function * diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 661c81df51..7d270b5b82 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -26,6 +26,12 @@ $htmlHeadXtra[] = '