diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index b685003f8c..346b78aed5 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -1597,6 +1597,7 @@ class Agenda * @param array $sendTo array('users' => [1, 2], 'groups' => [3, 4]) * @param array $attributes * @param bool $addOnlyItemsInSendTo + * @param bool $required */ public function setSendToSelect( $form, @@ -1604,7 +1605,8 @@ class Agenda $userList = null, $sendTo = array(), $attributes = array(), - $addOnlyItemsInSendTo = false + $addOnlyItemsInSendTo = false, + $required = false ) { $params = array( 'id' => 'users_to_send_id', @@ -1625,7 +1627,11 @@ class Agenda $sendToUsers = isset($sendTo['users']) ? $sendTo['users'] : array(); /** @var HTML_QuickForm_select $select */ - $select = $form->addElement('select', 'users_to_send', get_lang('To'), null, $params); + $select = $form->addSelect('users_to_send', get_lang('To'), null, $params); + + if ($required) { + $form->setRequired($select); + } $selectedEveryoneOptions = array(); if (isset($sendTo['everyone']) && $sendTo['everyone']) { @@ -1799,7 +1805,7 @@ class Agenda } else { $sendTo = isset($params['send_to']) ? $params['send_to'] : null; if ($this->type == 'course') { - $this->showToForm($form, $sendTo); + $this->showToForm($form, $sendTo, array(), false, true); } } @@ -1902,13 +1908,15 @@ class Agenda * @param array $sendTo array('everyone' => false, 'users' => [1, 2], 'groups' => [3, 4]) * @param array $attributes * @param bool $addOnlyItemsInSendTo + * @param bool $required * @return bool */ public function showToForm( $form, $sendTo = array(), $attributes = array(), - $addOnlyItemsInSendTo = false + $addOnlyItemsInSendTo = false, + $required = false ) { if ($this->type != 'course') { return false; @@ -1936,8 +1944,10 @@ class Agenda $userList, $sendTo, $attributes, - $addOnlyItemsInSendTo + $addOnlyItemsInSendTo, + $required ); + return true; } @@ -2246,8 +2256,7 @@ class Agenda ); $selectedValues = $this->parseAgendaFilter($filter); $this->showToForm($form, $selectedValues, $attributes); - $form = $form->return_form(); - + $form = $form->returnForm(); } $actions .= "". Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM).""; diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index 2577a19956..f87b856e83 100755 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -1636,7 +1636,7 @@ class Attendance $users = $this->get_users_rel_course(); $user_ids = array_keys($users); $course_id = api_get_course_int_id(); - + $affected_rows = 0; if ($all_delete) { $attendance_calendar = $this->get_attendance_calendar($attendance_id); // get all dates from calendar by current attendance diff --git a/main/inc/lib/database.constants.inc.php b/main/inc/lib/database.constants.inc.php index 432662be50..ec59e713ea 100755 --- a/main/inc/lib/database.constants.inc.php +++ b/main/inc/lib/database.constants.inc.php @@ -116,9 +116,6 @@ define('TABLE_MAIN_SESSION_FIELD', 'session_field'); define('TABLE_MAIN_SESSION_FIELD_OPTIONS', 'session_field_options'); define('TABLE_MAIN_SESSION_FIELD_VALUES', 'session_field_values'); -// Message -define('TABLE_MAIN_MESSAGE', 'message'); - // Term and conditions define('TABLE_MAIN_LEGAL', 'legal'); diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index a17bfdf301..8bc7895d86 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -2054,6 +2054,7 @@ class Display * @param string $title * @param string $footer * @param string $style + * * @return string */ public static function panel($content, $title = '', $footer = '', $style = '') diff --git a/main/inc/lib/formvalidator/Element/DateRangePicker.php b/main/inc/lib/formvalidator/Element/DateRangePicker.php index 197efc0e48..970bc7765f 100755 --- a/main/inc/lib/formvalidator/Element/DateRangePicker.php +++ b/main/inc/lib/formvalidator/Element/DateRangePicker.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ /** - * Form element to select a date and hour (with popup datepicker) + * Form element to select a range of dates (with popup datepicker) */ class DateRangePicker extends HTML_QuickForm_text { @@ -21,7 +21,7 @@ class DateRangePicker extends HTML_QuickForm_text } /** - * HTML code to display this datepicker + * @return string */ public function toHtml() { @@ -100,10 +100,12 @@ class DateRangePicker extends HTML_QuickForm_text { $dates = explode('/', $dateRange); $dates = array_map('trim', $dates); + $start = isset($dates[0]) ? $dates[0] : ''; + $end = isset($dates[1]) ? $dates[1] : ''; return array( - 'start' => $dates[0], - 'end' => $dates[1] + 'start' => $start, + 'end' => $end ); } @@ -117,6 +119,7 @@ class DateRangePicker extends HTML_QuickForm_text if (empty($dates['start']) || empty($dates['end'])) { return false; } + $format = 'Y-m-d H:i'; $d = DateTime::createFromFormat($format, $dates['start']); $resultStart = $d && $d->format($format) == $dates['start']; diff --git a/main/inc/lib/formvalidator/Element/SelectAjax.php b/main/inc/lib/formvalidator/Element/SelectAjax.php index dff8633cfb..b71e6b70f9 100644 --- a/main/inc/lib/formvalidator/Element/SelectAjax.php +++ b/main/inc/lib/formvalidator/Element/SelectAjax.php @@ -11,7 +11,7 @@ class SelectAjax extends HTML_QuickForm_select */ function SelectAjax($elementName = null, $elementLabel = null, $options = null, $attributes = null) { - parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes); + parent::__construct($elementName, $elementLabel, $options, $attributes); } /** diff --git a/main/inc/lib/formvalidator/Element/SelectLanguage.php b/main/inc/lib/formvalidator/Element/SelectLanguage.php index 43893a557c..1c7cc6be17 100644 --- a/main/inc/lib/formvalidator/Element/SelectLanguage.php +++ b/main/inc/lib/formvalidator/Element/SelectLanguage.php @@ -14,7 +14,7 @@ class SelectLanguage extends HTML_QuickForm_select if (!isset($attributes['class'])) { $attributes['class'] = 'chzn-select'; } - parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes); + parent::__construct($elementName, $elementLabel, $options, $attributes); // Get all languages $languages = api_get_languages(); $this->_options = array(); diff --git a/main/inc/lib/formvalidator/Element/SelectTheme.php b/main/inc/lib/formvalidator/Element/SelectTheme.php index d874266770..903a259814 100644 --- a/main/inc/lib/formvalidator/Element/SelectTheme.php +++ b/main/inc/lib/formvalidator/Element/SelectTheme.php @@ -11,10 +11,10 @@ class SelectTheme extends HTML_QuickForm_select */ function SelectTheme($elementName=null, $elementLabel=null, $options=null, $attributes=null) { if (!isset($attributes['class'])) { - //todo this was comment due a bug in infocours.php with jquery-ui + //todo this was comment due a bug in infocours.php with jquery-ui //$attributes['class'] = 'chzn-select'; - } - parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes); + } + parent::__construct($elementName, $elementLabel, $options, $attributes); // Get all languages $themes = api_get_themes(); $this->_options = array(); @@ -22,6 +22,6 @@ class SelectTheme extends HTML_QuickForm_select $this->addOption('--',''); // no theme select for ($i=0; $i< count($themes[0]);$i++) { $this->addOption($themes[1][$i],$themes[0][$i]); - } + } } -} \ No newline at end of file +} diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index f5525c097a..fb9eb6855d 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -576,7 +576,7 @@ EOT; /** * @param string $name * @param string $label - * @param array $options + * @param array $options * @param array $attributes * * @return HTML_QuickForm_select diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index dac6c1f0f6..941a1a8e84 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -884,16 +884,20 @@ class MessageManager $message_content .= $user_image.' '; } + $receiverUserInfo = api_get_user_info($row['user_receiver_id']); + $message_content .=''; if (api_get_setting('allow_social_tool') == 'true') { if ($source == 'outbox') { - $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '.GetFullUserName($row[2]).''; + $message_content .= get_lang('From').': '.$name.' '. + api_strtolower(get_lang('To')).' '.$receiverUserInfo['complete_name'].''; } else { - $message_content .= get_lang('From').' '.$name.' '.api_strtolower(get_lang('To')).' '.get_lang('Me').''; + $message_content .= get_lang('From').' '.$name.' '. + api_strtolower(get_lang('To')).' '.get_lang('Me').''; } } else { if ($source == 'outbox') { - $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '.GetFullUserName($row['user_receiver_id']).''; + $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '.$receiverUserInfo['complete_name'].''; } else { $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '.get_lang('Me').''; } diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php index 4c4bd55797..2fecedfd85 100755 --- a/main/inc/lib/pear/HTML/QuickForm.php +++ b/main/inc/lib/pear/HTML/QuickForm.php @@ -77,6 +77,7 @@ define('QUICKFORM_INVALID_DATASOURCE', -9); // }}} /** + * Class HTML_QuickForm * Create, validate and process HTML forms * * @category HTML @@ -98,7 +99,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_elements = array(); + public $_elements = array(); /** * Array containing element name to index map @@ -106,7 +107,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_elementIndex = array(); + public $_elementIndex = array(); /** * Array containing indexes of duplicate elements @@ -114,7 +115,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_duplicateIndex = array(); + public $_duplicateIndex = array(); /** * Array containing required field IDs @@ -122,7 +123,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_required = array(); + public $_required = array(); /** * Prefix message in javascript alert if error @@ -130,7 +131,7 @@ class HTML_QuickForm extends HTML_Common * @var string * @access public */ - var $_jsPrefix = 'Invalid information entered.'; + public $_jsPrefix = 'Invalid information entered.'; /** * Postfix message in javascript alert if error @@ -138,7 +139,7 @@ class HTML_QuickForm extends HTML_Common * @var string * @access public */ - var $_jsPostfix = 'Please correct these fields.'; + public $_jsPostfix = 'Please correct these fields.'; /** * Datasource object implementing the informal @@ -147,7 +148,7 @@ class HTML_QuickForm extends HTML_Common * @var object * @access private */ - var $_datasource; + public $_datasource; /** * Array of default form values @@ -155,7 +156,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_defaultValues = array(); + public $_defaultValues = array(); /** * Array of constant form values @@ -163,7 +164,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_constantValues = array(); + public $_constantValues = array(); /** * Array of submitted form values @@ -171,7 +172,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_submitValues = array(); + public $_submitValues = array(); /** * Array of submitted form files @@ -179,7 +180,7 @@ class HTML_QuickForm extends HTML_Common * @var integer * @access public */ - var $_submitFiles = array(); + public $_submitFiles = array(); /** * Value for maxfilesize hidden element if form contains file input @@ -187,7 +188,7 @@ class HTML_QuickForm extends HTML_Common * @var integer * @access public */ - var $_maxFileSize = 1048576; // 1 Mb = 1048576 + public $_maxFileSize = 1048576; // 1 Mb = 1048576 /** * Flag to know if all fields are frozen @@ -195,7 +196,7 @@ class HTML_QuickForm extends HTML_Common * @var boolean * @access private */ - var $_freezeAll = false; + public $_freezeAll = false; /** * Array containing the form rules @@ -203,14 +204,14 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_rules = array(); + public $_rules = array(); /** * Form rules, global variety * @var array * @access private */ - var $_formRules = array(); + public $_formRules = array(); /** * Array containing the validation errors @@ -218,7 +219,7 @@ class HTML_QuickForm extends HTML_Common * @var array * @access private */ - var $_errors = array(); + public $_errors = array(); /** * Note for required fields in the form @@ -226,14 +227,14 @@ class HTML_QuickForm extends HTML_Common * @since 1.0 * @access private */ - var $_requiredNote = '* denotes required field'; + public $_requiredNote = '* denotes required field'; /** * Whether the form was submitted * @var boolean * @access private */ - var $_flagSubmitted = false; + public $_flagSubmitted = false; // }}} // {{{ constructor @@ -258,7 +259,12 @@ class HTML_QuickForm extends HTML_Common if (isset($attributes['id']) && !empty($attributes['id'])) { $form_id = Security::remove_XSS($attributes['id']); } - $attributes = array('action'=>$action, 'method'=>$method, 'name'=>$formName, 'id'=>$form_id) + $target; + $attributes = array( + 'action' => $action, + 'method' => $method, + 'name' => $formName, + 'id' => $form_id + ) + $target; $this->updateAttributes($attributes); if (!$trackSubmit || isset($_REQUEST['_qf__' . $formName])) { if (1 == get_magic_quotes_gpc()) { @@ -2059,8 +2065,14 @@ class HTML_QuickForm extends HTML_Common return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[QUICKFORM_ERROR]; } // end func errorMessage - // }}} -} // end class HTML_QuickForm + /** + * @param HTML_QuickForm_element $element + */ + public function setRequired(HTML_QuickForm_element $element) + { + $this->addRule($element->getName(), get_lang('ThisFieldIsRequired'), 'required'); + } +} /** * Class for errors thrown by HTML_QuickForm package @@ -2101,6 +2113,4 @@ class HTML_QuickForm_Error extends PEAR_Error { $this->PEAR_Error("Invalid error code: $code", QUICKFORM_ERROR, $mode, $level, $debuginfo); } } - // }}} -} // end class HTML_QuickForm_Error -?> +} diff --git a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php index e899bd1434..9b74b0632e 100755 --- a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php +++ b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php @@ -282,7 +282,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $opts = $options; $options = null; // prevent to use the default select element load options - $this->HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes); + parent::__construct($elementName, $elementLabel, $options, $attributes); $this->selectAllCheckBox = isset($attributes['select_all_checkbox']) ? $attributes['select_all_checkbox'] : false; diff --git a/main/inc/lib/pear/HTML/QuickForm/select.php b/main/inc/lib/pear/HTML/QuickForm/select.php index 80d85d6590..aa08d1b35c 100755 --- a/main/inc/lib/pear/HTML/QuickForm/select.php +++ b/main/inc/lib/pear/HTML/QuickForm/select.php @@ -73,7 +73,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element * @access public * @return void */ - public function HTML_QuickForm_select( + public function __construct( $elementName = null, $elementLabel = null, $options = null, diff --git a/main/inc/lib/pear/HTML/QuickForm/textarea.php b/main/inc/lib/pear/HTML/QuickForm/textarea.php index e208a1995d..5e33b39840 100755 --- a/main/inc/lib/pear/HTML/QuickForm/textarea.php +++ b/main/inc/lib/pear/HTML/QuickForm/textarea.php @@ -42,7 +42,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element * @since 1.0 * @access private */ - var $_value = null; + public $_value = null; // }}} // {{{ constructor @@ -185,7 +185,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element * @access public * @return string */ - function toHtml() + public function toHtml() { if ($this->_flagFrozen) { return $this->getFrozenHtml(); @@ -199,10 +199,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element // ''; } - } //end func toHtml - - // }}} - // {{{ getFrozenHtml() + } /** * Returns the value of field without HTML tags (in this case, value is changed to a mask) @@ -211,7 +208,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element * @access public * @return string */ - function getFrozenHtml() + public function getFrozenHtml() { // Modified by Ivan Tcholakov, 16-MAR-2010. //$value = htmlspecialchars($this->getValue()); @@ -223,9 +220,6 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element $html = nl2br($value)."\n"; } return $html . $this->_getPersistantData(); - } //end func getFrozenHtml - - // }}} + } -} //end class HTML_QuickForm_textarea -?> +} diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index a7efeea986..316cd7bfe5 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -11,6 +11,9 @@ */ class SocialManager extends UserManager { + /** + * Constructor + */ public function __construct() { @@ -25,7 +28,8 @@ class SocialManager extends UserManager { $friend_relation_list = array(); $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); - $sql = 'SELECT id,title FROM '.$tbl_my_friend_relation_type.' WHERE id<>6 ORDER BY id ASC'; + $sql = 'SELECT id,title FROM '.$tbl_my_friend_relation_type.' + WHERE id<>6 ORDER BY id ASC'; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $friend_relation_list[] = $row; @@ -100,14 +104,23 @@ class SocialManager extends UserManager $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER); $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER); $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' - WHERE relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND friend_user_id<>'.((int) $user_id).' AND user_id='.((int) $user_id); + WHERE + relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND + friend_user_id<>'.((int) $user_id).' AND + user_id='.((int) $user_id); if (isset($id_group) && $id_group > 0) { $sql.=' AND relation_type='.$id_group; } if (isset($search_name)) { $search_name = trim($search_name); $search_name = str_replace(' ', '', $search_name); - $sql.=' AND friend_user_id IN (SELECT user_id FROM '.$tbl_my_user.' WHERE firstName LIKE "%'.Database::escape_string($search_name).'%" OR lastName LIKE "%'.Database::escape_string($search_name).'%" OR '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' like concat("%","'.Database::escape_string($search_name).'","%") ) '; + $sql.=' AND friend_user_id IN ( + SELECT user_id FROM '.$tbl_my_user.' + WHERE + firstName LIKE "%'.Database::escape_string($search_name).'%" OR + lastName LIKE "%'.Database::escape_string($search_name).'%" OR + '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") + ) '; } $res = Database::query($sql); @@ -144,7 +157,12 @@ class SocialManager extends UserManager $list_ids = self::get_friends($user_id, $id_group, $search_name); if (is_array($list_ids)) { foreach ($list_ids as $values_ids) { - $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['friend_user_id'], 'web', false, true); + $list_path_image_friend[] = UserManager::get_user_picture_path_by_id( + $values_ids['friend_user_id'], + 'web', + false, + true + ); $combine_friend = array( 'id_friend' => $list_ids, 'path_friend' => $list_path_image_friend @@ -189,7 +207,7 @@ class SocialManager extends UserManager */ public static function send_invitation_friend($user_id, $friend_id, $message_title, $message_content) { - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $user_id = intval($user_id); $friend_id = intval($friend_id); @@ -202,7 +220,11 @@ class SocialManager extends UserManager $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);'; + 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'); @@ -249,9 +271,11 @@ class SocialManager extends UserManager */ public static function get_message_number_invitation_by_user_id($user_receiver_id) { - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.' - WHERE user_receiver_id='.intval($user_receiver_id).' AND msg_status='.MESSAGE_STATUS_INVITATION_PENDING; + WHERE + user_receiver_id='.intval($user_receiver_id).' AND + msg_status='.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); $row = Database::fetch_array($res, 'ASSOC'); return $row['count_message_in_box']; @@ -265,10 +289,12 @@ class SocialManager extends UserManager */ public static function get_list_invitation_of_friends_by_user_id($user_id) { - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT user_sender_id,send_date,title,content FROM '.$tbl_message.' - WHERE user_receiver_id='.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; + WHERE + user_receiver_id='.intval($user_id).' AND + msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); $list_friend_invitation = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { @@ -286,7 +312,7 @@ class SocialManager extends UserManager public static function get_list_invitation_sent_by_user_id($user_id) { $list_friend_invitation = array(); - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT user_receiver_id, send_date,title,content FROM '.$tbl_message.' WHERE user_sender_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; @@ -306,7 +332,7 @@ class SocialManager extends UserManager */ public static function invitation_accepted($user_send_id, $user_receiver_id) { - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = "UPDATE $tbl_message SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." WHERE @@ -325,7 +351,7 @@ class SocialManager extends UserManager */ public static function invitation_denied($user_send_id, $user_receiver_id) { - $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'DELETE FROM '.$tbl_message.' WHERE user_sender_id = '.((int) $user_send_id).' AND @@ -420,7 +446,11 @@ class SocialManager extends UserManager if (!empty($rss->items)) { $icon_rss = ''; if (!empty($feed)) { - $icon_rss = Display::url(Display::return_icon('social_rss.png', '', array(), 22), Security::remove_XSS($feed['rssfeeds']), array('target' => '_blank')); + $icon_rss = Display::url( + Display::return_icon('social_rss.png', '', array(), 22), + Security::remove_XSS($feed['rssfeeds']), + array('target' => '_blank') + ); } $res .= '

'.$icon_rss.' '.$rss->channel['title'].'

'; @@ -1118,7 +1148,7 @@ class SocialManager extends UserManager */ public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0 ,$messageStatus) { - $tblMessage = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tblMessage = Database::get_main_table(TABLE_MESSAGE); $userId = intval($userId); $friendId = intval($friendId); $messageId = intval($messageId); @@ -1217,24 +1247,23 @@ class SocialManager extends UserManager if (empty($start)) { $start = '0000-00-00'; } - $tblMessage = Database::get_main_table(TABLE_MAIN_MESSAGE); + $tblMessage = Database::get_main_table(TABLE_MESSAGE); + $tblMessageAttachement = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); + $userId = intval($userId); $start = Database::escape_string($start); - // TODO: set a maximum of 3 months for messages - //if ($start == '0000-00-00') { - // - //} $limit = intval($limit); - $messages = array(); + $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id, - (SELECT ma.path from message_attachment ma WHERE ma.message_id = tm.id ) as path, - (SELECT ma.filename from message_attachment ma WHERE ma.message_id = tm.id ) as filename - FROM $tblMessage tm - WHERE user_receiver_id = $userId + (SELECT ma.path FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as path, + (SELECT ma.filename FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as filename + FROM $tblMessage tm + WHERE user_receiver_id = $userId AND send_date > '$start' "; $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' "; $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' "; $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit "; + $messages = array(); $res = Database::query($sql); if (Database::num_rows($res) > 0) { while ($row = Database::fetch_array($res)) { @@ -1284,7 +1313,7 @@ class SocialManager extends UserManager if ($isOwnWall) { $media .= '
'; $media .= ''.get_lang('x').''; + $message['id'].'">x'; $media .= '
'; } $media .= '
'; @@ -1404,11 +1433,10 @@ class SocialManager extends UserManager $wallImage = ''; } - $htmlDelete = ''; if ($isOwnWall) { $htmlDelete .= ''.get_lang('x').''; + $message['id'].'">x'; } $html = ''; @@ -1523,6 +1551,7 @@ class SocialManager extends UserManager /** * Generate the social block for a user + * @param Template $template * @param int $userId The user id * @param string $groupBlock Optional. Highlight link possible values: * group_add, home, messages, messages_inbox, messages_compose, @@ -1530,7 +1559,7 @@ class SocialManager extends UserManager * @param int $groupId Optional. Group ID * @return string The HTML code with the social block */ - public static function setSocialUserBlock($template, $userId, $groupBlock = '', $groupId = 0) + public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0) { if (api_get_setting('allow_social_tool') != 'true') { return ''; @@ -1548,4 +1577,106 @@ class SocialManager extends UserManager $template->assign('profileEditionLink', $profileEditionLink); $template->assign('social_avatar_block', $template->fetch('default/social/user_block.tpl')); } + + /** + * @param $user_id + * @param $link_shared + * @param $show_full_profile + * @return string + */ + public static function listMyFriends($user_id, $link_shared, $show_full_profile) + { + //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT + $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND); + $number_of_images = 30; + $number_friends = count($friends); + + $friendHtml = ''; + + if ($number_friends != 0) { + if ($number_friends > $number_of_images) { + if (api_get_user_id() == $user_id) { + $friendHtml.= ' : '.get_lang('SeeAll').''; + } else { + $friendHtml.= ' : ' + .''.get_lang('SeeAll').''; + } + } + + $friendHtml.= ''; + } else { + $friendHtml.= '
'.get_lang('NoFriendsInYourContactList').'
' + .''. get_lang('TryAndFindSomeFriends').'
'; + } + + return $friendHtml; + } + + /** + * @return string + */ + public static function getWallForm() + { + $form = new FormValidator( + 'social_wall_main', + 'post', + api_get_path(WEB_CODE_PATH).'social/profile.php', + null, + array('enctype' => 'multipart/form-data') + ); + + $form->addTextarea('social_wall_new_msg_main', null, array('placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'))); + $form->addButtonSend(get_lang('Post')); + $html = Display::panel($form->returnForm(), get_lang('SocialWall')); + + return $html; + } + + /** + * @param int $userId + * @param int $friendId + * @return string + */ + public static function getWallMessagesByUser($userId, $friendId) + { + $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId); + $html = ''; + + foreach ($messages as $message) { + $post = $message['html']; + $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']); + + $html .= $post.$comment; + } + + return $html; + } } diff --git a/main/inc/lib/statistics.lib.php b/main/inc/lib/statistics.lib.php index 5ee2c63d40..50eb4758a7 100644 --- a/main/inc/lib/statistics.lib.php +++ b/main/inc/lib/statistics.lib.php @@ -703,7 +703,7 @@ class Statistics */ public static function getMessages($messageType) { - $message_table = Database::get_main_table(TABLE_MAIN_MESSAGE); + $message_table = Database::get_main_table(TABLE_MESSAGE); $user_table = Database::get_main_table(TABLE_MAIN_USER); $access_url_rel_user_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 26183fe95c..72691c2dfe 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -4062,7 +4062,7 @@ class UserManager public static function remove_user_rel_user($friend_id, $real_removed = false, $with_status_condition = '') { $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER); - $tbl_my_message = Database :: get_main_table(TABLE_MAIN_MESSAGE); + $tbl_my_message = Database :: get_main_table(TABLE_MESSAGE); $friend_id = intval($friend_id); if ($real_removed) { diff --git a/main/messages/new_message.php b/main/messages/new_message.php index cf8d0b4a6b..d231ea0eb5 100755 --- a/main/messages/new_message.php +++ b/main/messages/new_message.php @@ -118,7 +118,7 @@ $nameTools = get_lang('ComposeMessage'); /** * Shows the compose area + a list of users to select from. */ -function show_compose_to_any ($user_id) { +function show_compose_to_any($user_id) { $online_user_list = MessageManager::get_online_user_list($user_id); $default['user_list'] = 0; $online_user_list=null; @@ -129,26 +129,23 @@ function show_compose_to_any ($user_id) { function show_compose_reply_to_message($message_id, $receiver_id) { $table_message = Database::get_main_table(TABLE_MESSAGE); - $query = "SELECT user_sender_id FROM $table_message WHERE user_receiver_id=".intval($receiver_id)." AND id='".intval($message_id)."';"; + $query = "SELECT user_sender_id FROM $table_message + WHERE user_receiver_id=".intval($receiver_id)." AND id='".intval($message_id)."';"; $result = Database::query($query); $row = Database::fetch_array($result,'ASSOC'); if (!isset($row['user_sender_id'])) { $html = get_lang('InvalidMessageId'); + return $html; } - $pre_html = '
- -
'; - $post = '
'; - $sent_to = $pre_html.''.GetFullUserName($row['user_sender_id']).''.$post; + $userInfo = api_get_user_info($row['user_sender_id']); $default['users'] = array($row['user_sender_id']); - $html .= manage_form($default, null, $sent_to); + $html = manage_form($default, null, $userInfo['complete_name']); return $html; } function show_compose_to_user ($receiver_id) { - global $charset; $html = get_lang('To').': '.GetFullUserName($receiver_id).''; $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle')); $default['users'] = array($receiver_id); @@ -156,7 +153,8 @@ function show_compose_to_user ($receiver_id) { return $html; } -function manage_form($default, $select_from_user_list = null, $sent_to = null) { +function manage_form($default, $select_from_user_list = null, $sent_to = null) +{ $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null; @@ -169,7 +167,6 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) { get_lang('SendMessageTo'), true, array( - 'class' => 'span4', 'id'=>'id_text_name', 'onkeyup'=>'send_request_and_search()', 'autocomplete'=>'off' @@ -180,7 +177,7 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) { $form->addElement('hidden','user_list', 0, array('id'=>'user_list')); } else { if (!empty($sent_to)) { - $form->addElement('html',$sent_to); + $form->addLabel(get_lang('SendMessageTo'), $sent_to); } if (empty($default['users'])) { //fb select @@ -197,7 +194,7 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) { $form->addElement('hidden','parent_id',$message_id); } - $form->addText('title', get_lang('Subject'), true, array('class' => 'col-md-4')); + $form->addText('title', get_lang('Subject'), true); $form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250')); if (isset($_GET['re_id'])) { @@ -223,7 +220,7 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) { $form->addElement('advanced_settings',''.get_lang('AddOneMoreFile').' ('.sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize'))).')'); } - $form->addElement('style_submit_button','compose',api_xml_http_response_encode(' '.get_lang('SendMessage')),'class="btn-success"'); + $form->addButtonSend(get_lang('SendMessage'), 'compose'); $form->setRequiredNote('* '.get_lang('ThisFieldIsRequired').''); if (!empty($group_id) && !empty($message_id)) { @@ -270,13 +267,15 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) { $token = Security::get_token(); $form->addElement('hidden','sec_token'); $form->setConstants(array('sec_token' => $token)); - $html .= $form->return_form(); + $html .= $form->returnForm(); } return $html; } +$socialToolIsActive = isset($_GET['f']) && $_GET['f'] == 'social'; + /* MAIN SECTION */ -if ($_GET['f']=='social') { +if ($socialToolIsActive) { $this_section = SECTION_SOCIAL; $interbreadcrumb[]= array ('url' => api_get_path(WEB_PATH).'main/social/home.php','name' => get_lang('SocialNetwork')); } else { @@ -288,11 +287,13 @@ $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $social_right_content = null; if ($group_id != 0) { $social_right_content .= '
'; - $social_right_content .= ''.Display::return_icon('back.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).''; - $social_right_content .= ''.Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).''; + $social_right_content .= ''. + Display::return_icon('back.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).''; + $social_right_content .= ''. + Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).''; $social_right_content .= '
'; } else { - if ($_GET['f']=='social') { + if ($socialToolIsActive) { } else { $social_right_content .= '
'; if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') { @@ -329,7 +330,7 @@ if (!isset($_POST['compose'])) { } elseif(isset($_GET['send_to_user'])) { $social_right_content .= show_compose_to_user($_GET['send_to_user']); } else { - $social_right_content .= show_compose_to_any($_user['user_id']); + $social_right_content .= show_compose_to_any(api_get_user_id()); } } else { $restrict = false; diff --git a/main/messages/view_message.php b/main/messages/view_message.php index dfe34606c0..31525cb19d 100755 --- a/main/messages/view_message.php +++ b/main/messages/view_message.php @@ -75,7 +75,6 @@ $tpl = new Template(get_lang('View')); SocialManager::setSocialUserBlock($tpl, $user_id, $show_menu); if (api_get_setting('allow_social_tool') == 'true') { - $tpl->assign('social_avatar_block', $social_avatar_block); $tpl->assign('social_menu_block', $social_menu_block); $tpl->assign('social_right_content', $social_right_content); $social_layout = $tpl->get_template('social/inbox.tpl'); diff --git a/main/social/profile.php b/main/social/profile.php index 32738acbf5..d5d020fa30 100755 --- a/main/social/profile.php +++ b/main/social/profile.php @@ -236,7 +236,7 @@ foreach ($sessionList as $session) { } // My friends -$friend_html = listMyFriends($user_id, $link_shared ,$show_full_profile); +$friend_html = SocialManager::listMyFriends($user_id, $link_shared ,$show_full_profile); $social_left_content = ''; /* @@ -281,11 +281,11 @@ if ($show_full_profile) { */ //Social Block Wall -$wallSocialAddPost = wallSocialAddPost(); +$wallSocialAddPost = SocialManager::getWallForm(); $social_wall_block = $wallSocialAddPost; //Social Post Wall -$post_wall = wallSocialPost($my_user_id,$friendId) ; +$post_wall = SocialManager::getWallMessagesByUser($my_user_id, $friendId) ; $social_post_wall_block = '