示例#1
0
 /**
  * Creates a valid date format @b YYYY-MM-DD for the SQL statement
  * @param  string $date     The unformated date from user input e.g. @b 12.04.2012
  * @param  string $operator The actual operator for the @b date parameter
  * @return string String with a SQL valid date format @b YYYY-MM-DD
  */
 private function getFormatDate($date, $operator)
 {
     global $gPreferences;
     $formatDate = '';
     // if last char is Y or J then user searches for age
     $last = substr($date, -1);
     $last = admStrToUpper($last);
     if ($last === 'J' || $last === 'Y') {
         $age = (int) substr($date, 0, -1);
         $date = new DateTimeExtended(date('Y') . '-' . date('m') . '-' . date('d'), 'Y-m-d', 'date');
         $ageCondition = '';
         switch ($operator) {
             case '=':
                 // first remove = from destination condition
                 $this->mDestCond = substr($this->mDestCond, 0, strlen($this->mDestCond) - 4);
                 // now compute the dates for a valid birthday with that age
                 $date->modify('-' . $age . ' years');
                 $dateTo = $date->format('Y-m-d');
                 $date->modify('-1 year');
                 $date->modify('+1 day');
                 $dateFrom = $date->format('Y-m-d');
                 $ageCondition = ' BETWEEN \'' . $dateFrom . '\' AND \'' . $dateTo . '\'';
                 $this->mOpenQuotes = false;
                 break;
             case '}':
                 // search for dates that are older than the age
                 // because the age itself takes 1 year we must add 1 year and 1 day to age
                 $date->modify('-' . ($age + 1) . ' years');
                 $date->modify('+1 day');
                 $ageCondition = $date->format('Y-m-d');
                 break;
             case '{':
                 // search for dates that are younger than the age
                 // we must add 1 day to the date because the day itself belongs to the age
                 $date->modify('-' . $age . ' years');
                 $date->modify('+1 day');
                 $ageCondition = $date->format('Y-m-d');
                 break;
         }
         return $ageCondition;
     }
     // validate date and return it in database format
     if ($date !== '') {
         $date = new DateTimeExtended($date, $gPreferences['system_date']);
         if ($date->isValid()) {
             $formatDate = $date->format('Y-m-d');
         }
     }
     return $formatDate;
 }
示例#2
0
 }
 // wenn Datum-bis nicht gefüllt ist, dann mit Datum-von nehmen
 if (strlen($_POST['date_to']) == 0) {
     $_POST['date_to'] = $_POST['date_from'];
 }
 if (strlen($_POST['date_to_time']) == 0) {
     $_POST['date_to_time'] = $_POST['date_from_time'];
 }
 $endDateTime = new DateTimeExtended($_POST['date_to'] . ' ' . $_POST['date_to_time'], $gPreferences['system_date'] . ' ' . $gPreferences['system_time']);
 if ($endDateTime->isValid()) {
     // Datum & Uhrzeit formatiert zurueckschreiben
     $date->setValue('dat_end', $endDateTime->getDateTimeString());
 } else {
     // Fehler: pruefen, ob Datum oder Uhrzeit falsches Format hat
     $endDateTime = new DateTimeExtended($_POST['date_to'], $gPreferences['system_date']);
     if ($endDateTime->isValid()) {
         $gMessage->show($gL10n->get('SYS_DATE_INVALID', $gL10n->get('SYS_END'), $gPreferences['system_date']));
     } else {
         $gMessage->show($gL10n->get('SYS_TIME_INVALID', $gL10n->get('SYS_TIME') . ' ' . $gL10n->get('SYS_END'), $gPreferences['system_time']));
     }
 }
 // DateTo should be greater than DateFrom (Timestamp must be less)
 if ($startDateTime < $endDateTime) {
     $gMessage->show($gL10n->get('SYS_DATE_END_BEFORE_BEGIN'));
 }
 if (isset($_POST['dat_highlight']) == false) {
     $_POST['dat_highlight'] = 0;
 }
 if (isset($_POST['dat_global']) == false) {
     $_POST['dat_global'] = 0;
 }
     exit($gL10n->get('SYS_NO_RIGHTS'));
 }
 $formatedStartDate = '';
 $formatedEndDate = '';
 // Check das Beginn Datum
 $startDate = new DateTimeExtended($getMembershipStart, $gPreferences['system_date']);
 if ($startDate->isValid()) {
     // Datum formatiert zurueckschreiben
     $formatedStartDate = $startDate->format('Y-m-d');
 } else {
     exit($gL10n->get('SYS_DATE_INVALID', $gL10n->get('SYS_START'), $gPreferences['system_date']));
 }
 // Falls gesetzt wird das Enddatum gecheckt
 if ($getMembershipEnd !== '') {
     $endDate = new DateTimeExtended($getMembershipEnd, $gPreferences['system_date']);
     if ($endDate->isValid()) {
         // Datum formatiert zurueckschreiben
         $formatedEndDate = $endDate->format('Y-m-d');
     } else {
         exit($gL10n->get('SYS_DATE_INVALID', $gL10n->get('SYS_END'), $gPreferences['system_date']));
     }
     // If start-date is later/bigger or on same day than end-date we show an error
     if ($formatedStartDate > $formatedEndDate) {
         exit($gL10n->get('SYS_DATE_END_BEFORE_BEGIN'));
     }
 } else {
     $formatedEndDate = '9999-12-31';
 }
 // save role membership
 $user->editRoleMembership($getMemberId, $formatedStartDate, $formatedEndDate);
 echo 'success';
示例#4
0
 /** Returns the user value for this column @n
  *  format = 'd.m.Y' : a date or timestamp field accepts the format of the PHP date() function @n
  *  format = 'html'  : returns the value in html-format if this is necessary for that field type @n
  *  format = 'database' : returns the value that is stored in database with no format applied
  *  @param $fieldNameIntern Expects the @b usf_name_intern of table @b adm_user_fields
  *  @param $format Returns the field value in a special format @b text, @b html, @b database or datetime (detailed description in method description)
  */
 public function getValue($fieldNameIntern, $format = '')
 {
     global $gL10n, $gPreferences;
     $value = '';
     // exists a profile field with that name ?
     // then check if user has a data object for this field and then read value of this object
     if (array_key_exists($fieldNameIntern, $this->mProfileFields) && array_key_exists($this->mProfileFields[$fieldNameIntern]->getValue('usf_id'), $this->mUserData)) {
         $value = $this->mUserData[$this->mProfileFields[$fieldNameIntern]->getValue('usf_id')]->getValue('usd_value', $format);
         if ($format != 'database') {
             if ($this->mProfileFields[$fieldNameIntern]->getValue('usf_type') == 'DATE' && $value !== '') {
                 // if no format or html is set then show date format from Admidio settings
                 if ($format === '' || $format == 'html') {
                     $dateFormat = $gPreferences['system_date'];
                 } else {
                     $dateFormat = $format;
                 }
                 // if date field then the current date format must be used
                 $date = new DateTimeExtended($value, 'Y-m-d', 'date');
                 if (!$date->isValid()) {
                     return $value;
                 }
                 $value = $date->format($dateFormat);
             } elseif ($this->mProfileFields[$fieldNameIntern]->getValue('usf_type') == 'DROPDOWN' || $this->mProfileFields[$fieldNameIntern]->getValue('usf_type') == 'RADIO_BUTTON') {
                 // the value in db is only the position, now search for the text
                 if ($value > 0 && $format != 'html') {
                     $arrListValues = $this->mProfileFields[$fieldNameIntern]->getValue('usf_value_list');
                     $value = $arrListValues[$value];
                 }
             } elseif ($fieldNameIntern == 'COUNTRY' && $value !== '') {
                 // read the language name of the country
                 $value = $gL10n->getCountryByCode($value);
             }
         }
     }
     // get html output for that field type and value
     if ($format == 'html') {
         $value = $this->getHtmlValue($fieldNameIntern, $value);
     }
     return $value;
 }
示例#5
0
         }
     } else {
         $gMessage->show($gL10n->get('SYS_DATE_INVALID', $gL10n->get('ROL_VALID_FROM'), $gPreferences['system_date']));
     }
 }
 // Uhrzeit von/bis auf Gueltigkeit pruefen
 if (strlen($_POST['rol_start_time']) > 0) {
     $startTime = new DateTimeExtended($_POST['rol_start_time'], $gPreferences['system_time']);
     if ($startTime->isValid()) {
         $_POST['rol_start_time'] = $startTime->format('H:i:s');
     } else {
         $gMessage->show($gL10n->get('SYS_TIME_INVALID', $gL10n->get('ROL_TIME_FROM'), $gPreferences['system_time']));
     }
     if (strlen($_POST['rol_end_time']) > 0) {
         $endTime = new DateTimeExtended($_POST['rol_end_time'], $gPreferences['system_time']);
         if ($endTime->isValid()) {
             $_POST['rol_end_time'] = $endTime->format('H:i:s');
         } else {
             $gMessage->show($gL10n->get('SYS_TIME_INVALID', $gL10n->get('ROL_TIME_TO'), $gPreferences['system_time']));
         }
     } else {
         $gMessage->show($gL10n->get('SYS_FIELD_EMPTY', $gL10n->get('ROL_TIME_TO')));
     }
 }
 // Kontrollieren ob bei nachtraeglicher Senkung der maximalen Mitgliederzahl diese nicht bereits ueberschritten wurde
 if ($getRoleId > 0 && $_POST['rol_max_members'] != $role->getValue('rol_max_members')) {
     // Zaehlen wieviele Leute die Rolle bereits haben, ohne Leiter
     $role->setValue('rol_max_members', $_POST['rol_max_members']);
     $num_free_places = $role->countVacancies();
     if ($num_free_places < 0) {
         $gMessage->show($gL10n->get('SYS_ROLE_MAX_MEMBERS', $role->getValue('rol_name')));
示例#6
0
 /**
  * Method validates all date inputs and formats them to date format 'Y-m-d' needed for database queries
  * @param  string       $date Date to be validated and formated if needed
  * @return string|false
  */
 private function formatDate($date)
 {
     global $gPreferences;
     $objDate = new DateTimeExtended($date, 'Y-m-d', 'date');
     if ($objDate->isValid()) {
         return $date;
     } else {
         // check if date has system format
         $objDate = new DateTimeExtended($date, $gPreferences['system_date']);
         if ($objDate->isValid()) {
             return substr($objDate->getDateTimeString(), 0, 10);
         } else {
             return false;
         }
     }
 }
 /**
  * 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 false|void Returns false if invalid date format is submitted
  */
 public function setDateRange($dateRangeStart, $dateRangeEnd)
 {
     global $gPreferences;
     if ($dateRangeStart === '') {
         $dateRangeStart = '1970-01-01';
         $dateRangeEnd = DATE_NOW;
     }
     // Create date object and format date_from in English format and system format and push to daterange array
     $objDate = new DateTimeExtended($dateRangeStart, 'Y-m-d');
     if ($objDate->isValid()) {
         $this->setParameter('dateStartFormatEnglish', $objDate->format('Y-m-d'));
         $this->setParameter('dateStartFormatAdmidio', $objDate->format($gPreferences['system_date']));
     } else {
         // check if date_from  has system format
         $objDate = new DateTimeExtended($dateRangeStart, $gPreferences['system_date']);
         if ($objDate->isValid()) {
             $this->setParameter('dateStartFormatEnglish', $objDate->format('Y-m-d'));
             $this->setParameter('dateStartFormatAdmidio', $objDate->format($gPreferences['system_date']));
         } else {
             return false;
         }
     }
     // Create date object and format date_to in English format and sytem format and push to daterange array
     $objDate = new DateTimeExtended($dateRangeEnd, 'Y-m-d');
     if ($objDate->isValid()) {
         $this->setParameter('dateEndFormatEnglish', $objDate->format('Y-m-d'));
         $this->setParameter('dateEndFormatAdmidio', $objDate->format($gPreferences['system_date']));
     } else {
         // check if date_from  has system format
         $objDate = new DateTimeExtended($dateRangeEnd, $gPreferences['system_date']);
         if ($objDate->isValid()) {
             $this->setParameter('dateEndFormatEnglish', $objDate->format('Y-m-d'));
             $this->setParameter('dateEndFormatAdmidio', $objDate->format($gPreferences['system_date']));
         } else {
             return false;
         }
     }
 }
示例#8
0
 /**
  * set value for column usd_value of field
  * @param $fieldNameIntern
  * @param $fieldValue
  * @return bool
  */
 public function setValue($fieldNameIntern, $fieldValue)
 {
     global $gPreferences;
     $returnCode = false;
     if ($fieldValue !== '') {
         switch ($this->mInventoryFields[$fieldNameIntern]->getValue('inf_type')) {
             case 'CHECKBOX':
                 // Checkbox darf nur 1 oder 0 haben
                 if ($fieldValue != 0 && $fieldValue != 1 && !$this->noValueCheck) {
                     return false;
                 }
                 break;
             case 'DATE':
                 // Datum muss gueltig sein und formatiert werden
                 $date = new DateTimeExtended($fieldValue, $gPreferences['system_date']);
                 if (!$date->isValid()) {
                     if (!$this->noValueCheck) {
                         return false;
                     }
                 } else {
                     $fieldValue = $date->format('Y-m-d');
                 }
                 break;
             case 'EMAIL':
                 // Email darf nur gueltige Zeichen enthalten und muss einem festen Schema entsprechen
                 $fieldValue = admStrToLower($fieldValue);
                 if (!strValidCharacters($fieldValue, 'email') && !$this->noValueCheck) {
                     return false;
                 }
                 break;
             case 'NUMBER':
                 // A number must be numeric
                 if (!is_numeric($fieldValue) && !$this->noValueCheck) {
                     return false;
                 } else {
                     // numbers don't have leading zero
                     $fieldValue = ltrim($fieldValue, '0');
                 }
                 break;
             case 'DECIMAL':
                 // A number must be numeric
                 if (!is_numeric(strtr($fieldValue, ',.', '00')) && !$this->noValueCheck) {
                     return false;
                 } else {
                     // numbers don't have leading zero
                     $fieldValue = ltrim($fieldValue, '0');
                 }
                 break;
             case 'URL':
                 // Homepage darf nur gueltige Zeichen enthalten
                 if (!strValidCharacters($fieldValue, 'url') && !$this->noValueCheck) {
                     return false;
                 }
                 // Homepage noch mit http vorbelegen
                 if (strpos(admStrToLower($fieldValue), 'http://') === false && strpos(admStrToLower($fieldValue), 'https://') === false) {
                     $fieldValue = 'http://' . $fieldValue;
                 }
                 break;
         }
     }
     $infId = $this->mInventoryFields[$fieldNameIntern]->getValue('inf_id');
     // first check if user has a data object for this field and then set value of this user field
     if (array_key_exists($infId, $this->mInventoryData)) {
         $returnCode = $this->mInventoryData[$infId]->setValue('ind_value', $fieldValue);
     } elseif (isset($this->mInventoryFields[$fieldNameIntern]) && $fieldValue !== '') {
         $this->mInventoryData[$infId] = new TableAccess($this->mDb, TBL_INVENT_DATA, 'ind');
         $this->mInventoryData[$infId]->setValue('ind_inf_id', $this->mInventoryFields[$fieldNameIntern]->getValue('inf_id'));
         $this->mInventoryData[$infId]->setValue('ind_itm_id', $this->mItemId);
         $returnCode = $this->mInventoryData[$infId]->setValue('ind_value', $fieldValue);
     }
     if ($returnCode && $this->mInventoryData[$infId]->hasColumnsValueChanged()) {
         $this->columnsValueChanged = true;
     }
     return $returnCode;
 }