1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
<?php
/**
***********************************************************************************************
* @copyright 2004-2016 The Admidio Team
* @see http://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
***********************************************************************************************
*/
/**
* @class ModuleAnnouncements
* @brief This class reads announcement recordsets from database
*
* This class reads all available recordsets from table announcements
* and returns an Array with results, recordsets and validated parameters from $_GET Array.
* @par Returned Array
* @code
* Array
* (
* [numResults] => 3
* [limit] => 10
* [totalCount] => 3
* [recordset] => Array
* (
* [0] => Array
* (
* [0] => 3
* [ann_id] => 3
* [1] => DEMO
* [ann_org_id] => 1
* [2] => 1
* [ann_global] => 1
* [3] => Willkommen im Demobereich
* [ann_headline] => Willkommen im Demobereich
* [4] => <p>In diesem Bereich kannst du mit Admidio herumspielen und schauen, ....</p>
* [ann_description] => <p>In diesem Bereich kannst du mit Admidio herumspielen und schauen, ....</p>
* [5] => 1
* [ann_usr_id_create] => 1
* [6] => 2013-07-18 00:00:00
* [ann_timestamp_create] => 2013-07-18 00:00:00
* [7] =>
* [ann_usr_id_change] =>
* [8] =>
* [ann_timestamp_change] =>
* [9] => Paul Webmaster
* [create_name] => Paul Webmaster
* [10] =>
* [change_name] =>
* )
* )
* [parameter] => Array
* (
* [active_role] => 1
* [calendar-selection] => 1
* [cat_id] => 0
* [category-selection] => 0,
* [date] => ''
* [daterange] => Array
* (
* [english] => Array
* (
* [start_date] => 2013-09-16 // current date
* [end_date] => 9999-12-31
* )
*
* [system] => Array
* (
* [start_date] => 16.09.2013 // current date
* [end_date] => 31.12.9999
* )
* )
* [headline] => Ankündigungen
* [id] => 0
* [mode] => Default
* [order] => 'ASC'
* [startelement] => 0
* [view_mode] => Default
* )
* )
* @endcode
*/
class ModuleAnnouncements extends Modules
{
protected $getConditions; ///< String with SQL condition
/**
* Get number of available announcements
* @Return int Returns the total count and push it in the array
*/
public function getDataSetCount()
{
global $gCurrentOrganization, $gDb;
$sql = 'SELECT COUNT(*) AS count
FROM '.TBL_ANNOUNCEMENTS.'
WHERE ( ann_org_id = '. $gCurrentOrganization->getValue('org_id'). '
OR ( ann_global = 1
AND ann_org_id IN ('.$gCurrentOrganization->getFamilySQL().') ))
'.$this->getConditions;
$pdoStatement = $gDb->query($sql);
return (int) $pdoStatement->fetchColumn();
}
/**
* Get all records and push it to the array
* @param int $startElement
* @param int $limit
* @return array Returns the Array with results, recordsets and validated parameters from $_GET Array
*/
public function getDataSet($startElement = 0, $limit = null)
{
global $gCurrentOrganization, $gPreferences, $gProfileFields, $gDb;
// Bedingungen
if($this->getParameter('id') > 0)
{
$this->getConditions = 'AND ann_id ='. $this->getParameter('id');
}
// Search announcements to date
elseif(strlen($this->getParameter('dateStartFormatEnglish')) > 0)
{
$this->getConditions = 'AND ann_timestamp_create BETWEEN \''.$this->getParameter('dateStartFormatEnglish').' 00:00:00\' AND \''.$this->getParameter('dateEndFormatEnglish').' 23:59:59\'';
}
if($gPreferences['system_show_create_edit'] == 1)
{
// show firstname and lastname of create and last change user
$additionalFields = '
cre_firstname.usd_value || \' \' || cre_surname.usd_value AS create_name,
cha_firstname.usd_value || \' \' || cha_surname.usd_value AS change_name ';
$additionalTables = '
LEFT JOIN '. TBL_USER_DATA .' cre_surname
ON cre_surname.usd_usr_id = ann_usr_id_create
AND cre_surname.usd_usf_id = '.$gProfileFields->getProperty('LAST_NAME', 'usf_id').'
LEFT JOIN '. TBL_USER_DATA .' cre_firstname
ON cre_firstname.usd_usr_id = ann_usr_id_create
AND cre_firstname.usd_usf_id = '.$gProfileFields->getProperty('FIRST_NAME', 'usf_id').'
LEFT JOIN '. TBL_USER_DATA .' cha_surname
ON cha_surname.usd_usr_id = ann_usr_id_change
AND cha_surname.usd_usf_id = '.$gProfileFields->getProperty('LAST_NAME', 'usf_id').'
LEFT JOIN '. TBL_USER_DATA .' cha_firstname
ON cha_firstname.usd_usr_id = ann_usr_id_change
AND cha_firstname.usd_usf_id = '.$gProfileFields->getProperty('FIRST_NAME', 'usf_id');
}
else
{
// show username of create and last change user
$additionalFields = ' cre_username.usr_login_name AS create_name,
cha_username.usr_login_name AS change_name ';
$additionalTables = '
LEFT JOIN '. TBL_USERS .' cre_username
ON cre_username.usr_id = ann_usr_id_create
LEFT JOIN '. TBL_USERS .' cha_username
ON cha_username.usr_id = ann_usr_id_change ';
}
// read announcements from database
$sql = 'SELECT ann.*, '.$additionalFields.'
FROM '.TBL_ANNOUNCEMENTS.' ann
'.$additionalTables.'
WHERE ( ann_org_id = '. $gCurrentOrganization->getValue('org_id'). '
OR ( ann_global = 1
AND ann_org_id IN ('.$gCurrentOrganization->getFamilySQL().') ))
'.$this->getConditions.'
ORDER BY ann_timestamp_create DESC';
// Check if limit was set
if($limit > 0)
{
$sql .= ' LIMIT '.$limit;
}
if($startElement > 0)
{
$sql .= ' OFFSET '.$startElement;
}
$announcementsStatement = $gDb->query($sql);
// array for results
return array(
'recordset' => $announcementsStatement->fetchAll(),
'numResults' => $announcementsStatement->rowCount(),
'limit' => $limit,
'totalCount' => $this->getDataSetCount(),
'parameter' => $this->getParameters()
);
}
/**
* Set a date range in which the dates should be searched. The method will fill
* 4 parameters @b dateStartFormatEnglish, @b dateStartFormatEnglish,
* @b dateEndFormatEnglish and @b dateEndFormatAdmidio that could be read with
* getParameter and could be used in the script.
* @param string $dateRangeStart A date in english or Admidio format that will be the start date of the range.
* @param string $dateRangeEnd A date in english or Admidio format that will be the end date of the range.
* @return bool Returns false if invalid date format is submitted
*/
public function setDateRange($dateRangeStart = '1970-01-01', $dateRangeEnd = DATE_NOW)
{
global $gPreferences;
if (!$this->setDateRangeParams($dateRangeStart, 'Start', 'Y-m-d'))
{
if (!$this->setDateRangeParams($dateRangeStart, 'Start', $gPreferences['system_date']))
{
return false;
}
}
if (!$this->setDateRangeParams($dateRangeEnd, 'End', 'Y-m-d'))
{
if (!$this->setDateRangeParams($dateRangeEnd, 'End', $gPreferences['system_date']))
{
return false;
}
}
return true;
}
/**
* @param string $dateRange
* @param string $dateRangePoint
* @param string $dateFormat
* @return bool
*/
private function setDateRangeParams($dateRange, $dateRangePoint, $dateFormat)
{
global $gPreferences;
$objDate = DateTime::createFromFormat($dateFormat, $dateRange);
if($objDate === false)
{
return false;
}
$this->setParameter('date' . $dateRangePoint . 'FormatEnglish', $objDate->format('Y-m-d'));
$this->setParameter('date' . $dateRangePoint . 'FormatAdmidio', $objDate->format($gPreferences['system_date']));
return true;
}
}