/** * Overloaded bind function to pre-process the params. * * @param array Named array * @return null|string null is operation was satisfactory, otherwise returns an error * @see JTable:bind * @since 1.3 */ public function bind($array, $ignore = '') { /** * Serialize Single Dates */ $dev_option = '0'; if (iCagendaHelper::isSerialized($array['dates'])) { $dates = unserialize($array['dates']); } elseif ($dev_option == '1') { $dates = $this->setDatesOptions($array['dates']); } else { $dates = $this->getDates($array['dates']); } rsort($dates); if ($dev_option == '1') { $array['dates'] = $array['dates']; } else { $array['dates'] = serialize($dates); } /** * Serialize Period Dates */ $nodate = '0000-00-00 00:00:00'; // Calcul des dates d'une période. $startdate = $array['startdate']; $enddate = $array['enddate']; if ($startdate == NULL) { $startdate = $nodate; } if ($enddate == NULL) { $enddate = $nodate; } if ($startdate == $nodate && $enddate != $nodate) { $enddate = $nodate; } $startcontrol = $this->mkt($startdate); $endcontrol = $this->mkt($enddate); $errorperiod = ''; if ($startcontrol > $endcontrol) { $errorperiod = '1'; } else { if (class_exists('DateInterval')) { // Create array with all dates of the period - PHP 5.3+ $start = new DateTime($startdate); $interval = '+1 days'; $date_interval = DateInterval::createFromDateString($interval); $timestartdate = date('H:i', strtotime($startdate)); $timeenddate = date('H:i', strtotime($enddate)); if ($timeenddate <= $timestartdate) { $end = new DateTime("{$enddate} +1 days"); } else { $end = new DateTime($enddate); } // Retourne toutes les dates. $perioddates = new DatePeriod($start, $date_interval, $end); $out = array(); } else { // Create array with all dates of the period - PHP 5.2 if ($startdate != $nodate && $enddate != $nodate) { $start = new DateTime($startdate); $timestartdate = date('H:i', strtotime($startdate)); $timeenddate = date('H:i', strtotime($enddate)); if ($timeenddate <= $timestartdate) { $end = new DateTime("{$enddate} +1 days"); } else { $end = new DateTime($enddate); } while ($start < $end) { $out[] = $start->format('Y-m-d H:i'); $start->modify('+1 day'); } } } // Prépare serialize. if (!empty($perioddates)) { foreach ($perioddates as $dt) { $out[] = $dt->format('Y-m-d H:i'); } } } // Serialize les dates de la période. if ($startdate != $nodate && $enddate != $nodate) { if ($errorperiod != '1') { $array['period'] = serialize($out); if (iCagendaHelper::isSerialized($array['period'])) { $period = unserialize($array['period']); } else { $period = $this->getPeriod($array['period']); } rsort($period); $array['period'] = serialize($period); } else { $array['period'] = ''; } } else { $array['period'] = ''; } /** * Set Week Days */ if (!isset($array['weekdays'])) { $array['weekdays'] = ''; } if (is_array($array['weekdays'])) { $array['weekdays'] = implode(',', $array['weekdays']); } /** * Create Next Date */ $todaytime = time(); $NextDates = $this->getNextDates($dates); if (isset($period)) { $NextPeriod = $this->getNextPeriod($period, $array['weekdays']); } else { $NextPeriod = $this->getNextDates($dates); } $today = time(); $day = date('d'); $m = date('m'); $y = date('y'); $hour = date('H'); $min = date('i'); $today = mktime(0, 0, 0, $m, $day, $y); $nextdmkt = strtotime($NextDates); $nextpmkt = strtotime($NextPeriod); $nextDmktdate = $this->mktdate($NextDates); $nextPmktdate = $this->mktdate($NextPeriod); $nextDmkttime = $this->mkttime($NextDates); $nextPmkttime = $this->mkttime($NextPeriod); // Controle Date à venir if ($nextDmktdate >= $today && $nextPmktdate >= $today) { if ($nextDmktdate < $nextPmktdate) { $array['next'] = $this->getNextDates($dates); } if ($nextDmktdate > $nextPmktdate) { $array['next'] = $this->getNextPeriod($period, $array['weekdays']); } if ($nextDmktdate == $nextPmktdate) { if ($nextDmkttime >= $nextPmkttime) { if (isset($period)) { $array['next'] = $this->getNextPeriod($period, $array['weekdays']); } else { $array['next'] = $this->getNextDates($dates); } } else { $array['next'] = $this->getNextDates($dates); } } } if ($nextDmktdate < $today && $nextPmktdate >= $today) { $array['next'] = $this->getNextPeriod($period, $array['weekdays']); } if ($nextDmktdate >= $today && $nextPmktdate < $today) { $array['next'] = $this->getNextDates($dates); } if ($nextDmktdate < $today && $nextPmktdate < $today) { if ($nextDmktdate < $nextPmktdate) { $array['next'] = $this->getNextPeriod($period, $array['weekdays']); } if ($nextDmktdate >= $nextPmktdate) { $array['next'] = $this->getNextDates($dates); } } // Control of dates if valid (EDIT SINCE VERSION 3.0 - update 3.1.4) if (($nextdmkt >= '943916400' and $nextdmkt <= '944002800') && $errorperiod == '1') { $array['next'] = '-3600'; } if (($nextdmkt == '943916400' or $nextdmkt == '943920000') && ($nextpmkt == '943916400' or $nextpmkt == '943920000')) { $array['next'] = '-3600'; } if ($array['next'] == '-3600') { $state = 0; $this->_db->setQuery('UPDATE `#__icagenda_events`' . ' SET `state` = ' . (int) $state . ' WHERE `id` = ' . (int) $array['id']); if (version_compare(JVERSION, '3.0', 'lt')) { $this->_db->query(); } else { $this->_db->execute(); } } /** * Set Creator infos */ $user = JFactory::getUser(); $userId = $user->get('id'); if ($array['created_by'] == '0') { $array['created_by'] = $userId; } if (isset($array['params']) && is_array($array['params'])) { // Convert the params field to a string. $parameter = new JRegistry(); $parameter->loadArray($array['params']); $array['params'] = (string) $parameter; } $username = $user->get('name'); $array['username'] = $username; /** * Set File upload */ if (!isset($array['file'])) { $file = JRequest::getVar('jform', null, 'files', 'array'); $fileUrl = $this->upload($file); $array['file'] = $fileUrl; } /** * Set Meta data */ if (isset($array['metadata']) && is_array($array['metadata'])) { $registry = new JRegistry(); $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } $mail_new_event = '0'; $mail_new_event = JComponentHelper::getParams('com_icagenda')->get('mail_new_event', '0'); $return[] = parent::bind($array, $ignore); if ($mail_new_event == 1) { $title = $array['title']; $id_event = $array['id']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS eventID')->from('#__icagenda_events')->order('id DESC'); $db->setQuery($query); $eventID = $db->loadResult(); $new_event = JRequest::getVar('new_event'); $title = $array['title']; $description = $array['desc']; $venue = ''; if ($array['place']) { $venue .= $array['place'] . ' - '; } if ($array['city']) { $venue .= $array['city']; } if ($array['city'] && $array['country']) { $venue .= ', '; } if ($array['country']) { $venue .= $array['country']; } if (strtotime($array['startdate'])) { $date = 'Du ' . $array['startdate'] . ' au ' . $array['startdate']; } else { $date = $array['next']; } $baseURL = JURI::base(); $baseURL = str_replace('/administrator', '', $baseURL); $baseURL = ltrim($baseURL, '/'); if ($array['image']) { $image = '<img src="' . $baseURL . '/' . $array['image'] . '" />'; } if ($new_event == '1' && $eventID && $array['state'] == '1' && $array['approval'] == '0') { $return[] = self::notificationNewEvent($eventID + 1, $title, $description, $venue, $date, $image, $new_event); } // elseif ($new_event == '0') // { // $return[] = self::notificationNewEvent($array['id'], 'Edited Event', $new_event); // } } return $return; }