public static function getMatchReportMessages(WebSoccer $websoccer, DbConnection $db, I18n $i18n, $matchId) { $fromTable = $websoccer->getConfig('db_prefix') . '_matchreport AS R'; $fromTable .= ' INNER JOIN ' . $websoccer->getConfig('db_prefix') . '_spiel_text AS T ON R.message_id = T.id'; $columns['R.id'] = 'report_id'; $columns['R.minute'] = 'minute'; $columns['R.playernames'] = 'playerNames'; $columns['R.goals'] = 'goals'; $columns['T.nachricht'] = 'message'; $columns['T.aktion'] = 'type'; $columns['R.active_home'] = 'active_home'; $whereCondition = 'R.match_id = %d ORDER BY R.minute DESC, R.id DESC'; $parameters = $matchId; $reportmessages = array(); $result = $db->querySelect($columns, $fromTable, $whereCondition, $parameters); $match = null; // required only for team name replacements $removeSlashes = get_magic_quotes_gpc(); while ($reportmessage = $result->fetch_array()) { // replace placeholders $players = explode(';', $reportmessage['playerNames']); $rmsg = $reportmessage['message']; // remove escaping slashes if ($removeSlashes) { $rmsg = stripslashes($rmsg); } $msgKey = strip_tags($rmsg); if ($i18n->hasMessage($msgKey)) { $rmsg = $i18n->getMessage($msgKey); } for ($playerIndex = 1; $playerIndex <= count($players); $playerIndex++) { $rmsg = str_replace('{sp' . $playerIndex . '}', $players[$playerIndex - 1], $rmsg); } // replace team name placeholders if (strpos($rmsg, '{ma1}') || strpos($rmsg, '{ma2}')) { if ($match == null) { $match = self::getMatchById($websoccer, $db, $matchId, FALSE); } if ($reportmessage['active_home']) { $rmsg = str_replace('{ma1}', $match['match_home_name'], $rmsg); $rmsg = str_replace('{ma2}', $match['match_guest_name'], $rmsg); } else { $rmsg = str_replace('{ma1}', $match['match_guest_name'], $rmsg); $rmsg = str_replace('{ma2}', $match['match_home_name'], $rmsg); } } $reportmessage['message'] = $rmsg; $reportmessages[] = $reportmessage; } $result->free(); return $reportmessages; }
/** * Retrieves the latest notifications for the specified user. * * @param WebSoccer $websoccer Application contex * @param DbConnection $db DB connection * @param I18n $i18n I18n context. * @param int $userId ID of user * @param int $teamId ID of user's currently selected team * @param int $limit maximum number of notifications to return. * @return array Array of assoc. arrays which represent a notification. A notification has keys id, eventdate, eventtype, seen, message, link */ public static function getLatestNotifications(WebSoccer $websoccer, DbConnection $db, I18n $i18n, $userId, $teamId, $limit) { $result = $db->querySelect('*', $websoccer->getConfig('db_prefix') . '_notification', 'user_id = %d AND (team_id = %d OR team_id IS NULL) ORDER BY eventdate DESC', array($userId, $teamId), $limit); $notifications = array(); while ($row = $result->fetch_array()) { $notification = array('id' => $row['id'], 'eventdate' => $row['eventdate'], 'eventtype' => $row['eventtype'], 'seen' => $row['seen']); // prepare message if ($i18n->hasMessage($row['message_key'])) { $message = $i18n->getMessage($row['message_key']); } else { $message = $row['message_key']; } // replace place holders if (strlen($row['message_data'])) { $messageData = json_decode($row['message_data'], true); if ($messageData) { foreach ($messageData as $placeholderName => $placeholderValue) { $message = str_replace('{' . $placeholderName . '}', htmlspecialchars($placeholderValue, ENT_COMPAT, 'UTF-8'), $message); } } } $notification['message'] = $message; // add target link $link = ''; if ($row['target_pageid']) { if ($row['target_querystr']) { $link = $websoccer->getInternalUrl($row['target_pageid'], $row['target_querystr']); } else { $link = $websoccer->getInternalUrl($row['target_pageid']); } } $notification['link'] = $link; $notifications[] = $notification; } return $notifications; }
/** * Renders a new form element. * * @param I18n $i18n Messages context. * @param string $fieldId ID of field. * @param array $fieldInfo Field configuration asan array. * @param string $fieldValue existing field value. * @param string $labelKeyPrefix prefix of i18n message key to use. Message key = labelKeyPrefix + field ID. */ public static function createFormGroup($i18n, $fieldId, $fieldInfo, $fieldValue, $labelKeyPrefix) { $type = $fieldInfo['type']; // convert date if ($type == 'timestamp' && isset($fieldInfo['readonly']) && $fieldInfo['readonly']) { $website = WebSoccer::getInstance(); $dateFormat = $website->getConfig('datetime_format'); // generate date if (!strlen($fieldValue)) { $fieldValue = date($dateFormat); } else { if (is_numeric($fieldValue)) { $fieldValue = date($dateFormat, $fieldValue); } } $type = 'text'; } else { if ($type == 'date' && strlen($fieldValue)) { if (StringUtil::startsWith($fieldValue, '0000')) { $fieldValue = ''; } else { $dateObj = DateTime::createFromFormat('Y-m-d', $fieldValue); if ($dateObj !== FALSE) { $website = WebSoccer::getInstance(); $dateFormat = $website->getConfig('date_format'); $fieldValue = $dateObj->format($dateFormat); } } } } echo '<div class=\'control-group\'>'; $helpText = ''; $inlineHelpKey = $labelKeyPrefix . $fieldId . '_help'; if ($i18n->hasMessage($inlineHelpKey)) { $helpText = '<span class=\'help-inline\'>' . $i18n->getMessage($inlineHelpKey) . '</span>'; } if ($type == 'boolean') { echo '<label class=\'checkbox\'>'; echo '<input type=\'checkbox\' value=\'1\' name=\'' . $fieldId . '\''; if ($fieldValue == '1') { echo ' checked'; } echo '>'; echo $i18n->getMessage($labelKeyPrefix . $fieldId); echo '</label>'; echo $helpText; } else { $labelOutput = $i18n->getMessage($labelKeyPrefix . $fieldId); if (isset($fieldInfo['required']) && $fieldInfo['required'] == 'true') { $labelOutput = '<strong>' . $labelOutput . '</strong>'; } echo '<label class=\'control-label\' for=\'' . $fieldId . '\'>' . $labelOutput . '</label>'; echo '<div class=\'controls\'>'; switch ($type) { // select from foreign DB table case 'foreign_key': self::createForeignKeyField($i18n, $fieldId, $fieldInfo, $fieldValue); break; // textarea // textarea case 'html': case 'textarea': $class = 'input-xxlarge'; if ($type == 'html') { $class = 'htmleditor'; } echo '<textarea id=\'' . $fieldId . '\' name=\'' . $fieldId . '\' wrap=\'virtual\' class=\'' . $class . '\' rows=\'10\'>' . $fieldValue . '</textarea>'; break; // date and time picker // date and time picker case 'timestamp': $website = WebSoccer::getInstance(); $dateFormat = $website->getConfig('date_format'); if (!$fieldValue) { $fieldValue = $website->getNowAsTimestamp(); } // time picker echo '<div class=\'input-append date datepicker\'>'; echo '<input type=\'text\' name=\'' . $fieldId . '_date\' value=\'' . date($dateFormat, $fieldValue) . '\' class=\'input-small\'>'; echo '<span class=\'add-on\'><i class=\'icon-calendar\'></i></span>'; echo '</div>'; echo '<div class=\'input-append bootstrap-timepicker\'>'; echo '<input type=\'text\' name=\'' . $fieldId . '_time\' value=\'' . date('H:i', $fieldValue) . '\' class=\'timepicker input-small\'>'; echo '<span class=\'add-on\'><i class=\'icon-time\'></i></span>'; echo '</div>'; break; // single selection from dropdown // single selection from dropdown case 'select': echo '<select id=\'' . $fieldId . '\' name=\'' . $fieldId . '\'>'; $selection = explode(',', $fieldInfo['selection']); $selectValue = $fieldValue; echo '<option></option>'; foreach ($selection as $selectItem) { $selectItem = trim($selectItem); echo '<option value=\'' . $selectItem . '\''; if ($selectItem == $selectValue) { echo ' selected'; } echo '>'; $label = $selectItem; if ($i18n->hasMessage('option_' . $selectItem)) { $label = $i18n->getMessage('option_' . $selectItem); } echo $label . '</option>'; } echo '</select>'; break; // all kind of text fields // all kind of text fields default: if (isset($fieldInfo['readonly']) && $fieldInfo['readonly']) { echo '<span class=\'uneditable-input\'>' . escapeOutput($fieldValue) . '</span>'; } else { $additionalAttrs = ''; $htmlType = $type; if ($type == 'file' && strlen($fieldValue)) { global $entity; echo '[<a href=\'../uploads/' . $entity . '/' . escapeOutput($fieldValue) . '\' target=\'_blank\'>View</a>] '; } else { if ($type == 'percent') { $htmlType = 'number'; $additionalAttrs = 'class=\'input-mini\' min=\'0\' '; } else { if ($type == 'number') { $additionalAttrs = 'class=\'input-small\' '; } else { if ($type == 'date') { if ($type == 'date') { echo '<div class=\'input-append date datepicker\'>'; } $htmlType = 'text'; $additionalAttrs = ' class=\'input-small\' '; } else { if ($type == 'tags') { $additionalAttrs = ' class=\'input-tag\' data-provide=\'tag\' '; } else { $additionalAttrs = 'placeholder=\'' . $i18n->getMessage($labelKeyPrefix . $fieldId) . '\' '; } } } } } echo '<input type=\'' . $htmlType . '\' id=\'' . $fieldId . '\' ' . $additionalAttrs . 'name=\'' . $fieldId . '\' value=\''; if ($type != 'password') { echo escapeOutput($fieldValue); } echo '\''; if (isset($fieldInfo['required']) && $fieldInfo['required']) { echo ' required'; } echo '>'; if ($type == 'date') { echo '<span class=\'add-on\'><i class=\'icon-calendar\'></i></span></div>'; } } } if ($type == 'percent') { echo ' % '; } echo $helpText; echo '</div>'; } echo '</div>'; }