function import_data($data, $overwrite, $type) { global $login, $count_con, $count_suc, $error_num, $ImportType, $LOG_CREATE; global $single_user, $single_user_login, $allow_conflicts; global $numDeleted, $errormsg; global $calUser, $H2COLOR, $sqlLog; $oldUIDs = array(); $oldIds = array(); $firstEventId = 0; $importId = 1; // Generate a unique import id $res = dbi_query("SELECT MAX(cal_import_id) FROM webcal_import"); if ($res) { if ($row = dbi_fetch_row($res)) { $importId = $row[0] + 1; } dbi_free_result($res); } $sql = "INSERT INTO webcal_import ( cal_import_id, cal_name, " . "cal_date, cal_type, cal_login ) VALUES ( {$importId}, NULL, " . date("Ymd") . ", '{$type}', '{$login}' )"; if (!dbi_query($sql)) { $errormsg = translate("Database error") . ": " . dbi_error(); return; } foreach ($data as $Entry) { $priority = 2; $participants[0] = $calUser; // Some additional date/time info $START = $Entry['StartTime'] > 0 ? localtime($Entry['StartTime']) : 0; $END = $Entry['EndTime'] > 0 ? localtime($Entry['EndTime']) : 0; $Entry['StartMinute'] = sprintf("%02d", $START[1]); $Entry['StartHour'] = sprintf("%02d", $START[2]); $Entry['StartDay'] = sprintf("%02d", $START[3]); $Entry['StartMonth'] = sprintf("%02d", $START[4] + 1); $Entry['StartYear'] = sprintf("%04d", $START[5] + 1900); $Entry['EndMinute'] = sprintf("%02d", $END[1]); $Entry['EndHour'] = sprintf("%02d", $END[2]); $Entry['EndDay'] = sprintf("%02d", $END[3]); $Entry['EndMonth'] = sprintf("%02d", $END[4] + 1); $Entry['EndYear'] = sprintf("%04d", $END[5] + 1900); if ($overwrite && !empty($Entry['UID'])) { $oldUIDs[$Entry['UID']]++; } // Check for untimed if ($Entry['Untimed'] == 1) { $Entry['StartMinute'] = ''; $Entry['StartHour'] = ''; $Entry['EndMinute'] = ''; $Entry['EndHour'] = ''; } // first check for any schedule conflicts if (empty($allow_conflicts) && $Entry['Duration'] != 0) { $date = mktime(0, 0, 0, $Entry['StartMonth'], $Entry['StartDay'], $Entry['StartYear']); $endt = !empty($Entry['Repeat']['EndTime']) ? $Entry['Repeat']['EndTime'] : 'NULL'; $dayst = !empty($Entry['Repeat']['RepeatDays']) ? $Entry['Repeat']['RepeatDays'] : "nnnnnnn"; $ex_days = array(); if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_days[] = date("Ymd", $ex_date); } } $dates = get_all_dates($date, RepeatType($Entry['Repeat']['Interval']), $endt, $dayst, $ex_days, $Entry['Repeat']['Frequency']); $overlap = overlap($dates, $Entry['Duration'], $Entry['StartHour'], $Entry['StartMinute'], $participants, $login, 0); } if (empty($error) && !empty($overlap)) { $error = translate("The following conflicts with the suggested time") . ":<ul>{$overlap}</ul>\n"; } if (empty($error)) { $updateMode = false; // See if event already is there from prior import. // The same UID is used for all events imported at once with iCal. // So, we still don't have enough info to find the exact // event we want to replace. We could just delete all // existing events that correspond to the UID. /************************************************************************ Not sure what to do with this code since I don't know how Palm and vCal use the UID stuff yet... if ( ! empty ( $Entry['UID'] ) ) { $res = dbi_query ( "SELECT webcal_import_data.cal_id " . "FROM webcal_import_data, webcal_entry_user " . "WHERE cal_import_type = 'ical' AND " . "webcal_import_data.cal_id = webcal_entry_user.cal_id AND " . "webcal_entry_user.cal_login = '******' AND " . "cal_external_id = '$Entry[UID]'" ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) { if ( ! empty ( $row[0] ) ) { $id = $row[0]; $updateMode = true; // update rather than add a new event } } } } ************************************************************************/ // Add the Event $res = dbi_query("SELECT MAX(cal_id) FROM webcal_entry"); if ($res) { $row = dbi_fetch_row($res); $id = $row[0] + 1; dbi_free_result($res); } else { $id = 1; //$error = "Unable to select MAX cal_id: " . dbi_error () . "<br /><br />\n<b>SQL:</b> $sql"; //break; } if ($firstEventId == 0) { $firstEventId = $id; } $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = "{$id}"; if (!$updateMode) { $names[] = 'cal_create_by'; $values[] = "'{$login}'"; } $names[] = 'cal_date'; $values[] = sprintf("%04d%02d%02d", $Entry['StartYear'], $Entry['StartMonth'], $Entry['StartDay']); $names[] = 'cal_time'; $values[] = $Entry['Untimed'] == 1 ? "-1" : sprintf("%02d%02d00", $Entry['StartHour'], $Entry['StartMinute']); $names[] = 'cal_mod_date'; $values[] = date("Ymd"); $names[] = 'cal_mod_time'; $values[] = date("Gis"); $names[] = 'cal_duration'; $values[] = sprintf("%d", $Entry['Duration']); $names[] = 'cal_priority'; $values[] = $priority; $names[] = 'cal_access'; $values[] = $Entry['Private'] == 1 ? "'R'" : "'P'"; $names[] = 'cal_type'; $values[] = $Entry['Repeat'] ? "'M'" : "'E'"; if (strlen($Entry['Summary']) == 0) { $Entry['Summary'] = translate("Unnamed Event"); } if (strlen($Entry['Description']) == 0) { $Entry['Description'] = $Entry['Summary']; } $Entry['Summary'] = str_replace("\\n", "\n", $Entry['Summary']); $Entry['Summary'] = str_replace("\\'", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\\"", "\"", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $names[] = 'cal_name'; $values[] = "'" . $Entry['Summary'] . "'"; $Entry['Description'] = str_replace("\\n", "\n", $Entry['Description']); $Entry['Description'] = str_replace("\\'", "'", $Entry['Description']); $Entry['Description'] = str_replace("\\\"", "\"", $Entry['Description']); $Entry['Description'] = str_replace("'", "\\'", $Entry['Description']); // limit length to 1024 chars since we setup tables that way if (strlen($Entry['Description']) >= 1024) { $Entry['Description'] = substr($Entry['Description'], 0, 1019) . "..."; } $names[] = 'cal_description'; $values[] = "'" . $Entry['Description'] . "'"; //echo "Summary:<p>" . nl2br ( htmlspecialchars ( $Entry['Summary'] ) ) . "</p>"; //echo "Description:<p>" . nl2br ( htmlspecialchars ( $Entry['Description'] ) ) . "</p>"; exit; if ($updateMode) { $sql = "UPDATE webcal_entry SET "; for ($f = 0; $f < count($names); $f++) { if ($f > 0) { $sql .= ", "; } $sql .= $names[$f] . " = " . $values[$f]; } $sql .= " WHERE cal_id = {$id}"; } else { $sql = "INSERT INTO webcal_entry ( " . implode(", ", $names) . " ) VALUES ( " . implode(", ", $values) . " )"; } if (empty($error)) { $sqlLog .= $sql . "<br />\n"; //echo "SQL: $sql <br />\n"; if (!dbi_query($sql)) { $error .= "<p>" . translate("Database error") . ": " . dbi_error() . "</p>\n"; break; } } // log add/update activity_log($id, $login, $login, $updateMode ? $LOG_UPDATE : $LOG_CREATE, "Import from {$ImportType}"); if ($single_user == "Y") { $participants[0] = $single_user_login; } // Now add to webcal_import_data if (!$updateMode) { if ($ImportType == "PALMDESKTOP") { $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'palm', '{$Entry['RecordID']}' )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } else { if ($ImportType == "VCAL") { $uid = empty($Entry['UID']) ? "null" : "'{$Entry['UID']}'"; if (strlen($uid) > 200) { $uid = "NULL"; } $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'vcal', {$uid} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } else { if ($ImportType == "ICAL") { $uid = empty($Entry['UID']) ? "null" : "'{$Entry['UID']}'"; if (strlen($uid) > 200) { $uid = "NULL"; } $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'ical', {$uid} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } } } } // Now add participants if (!$updateMode) { $status = $login == "__public__" ? 'W' : 'A'; if (empty($cat_id)) { $cat_id = 'NULL'; } $sql = "INSERT INTO webcal_entry_user " . "( cal_id, cal_login, cal_status, cal_category ) VALUES ( {$id}, '" . $participants[0] . "', '{$status}', {$cat_id} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } // Add repeating info if ($updateMode) { // remove old repeating info dbi_query("DELETE FROM webcal_entry_repeats WHERE cal_id = {$id}"); dbi_query("DELETE FROM webcal_entry_repeats_not WHERE cal_id = {$id}"); } if (!empty($Entry['Repeat']['Interval'])) { //while ( list($k,$v) = each ( $Entry['Repeat'] ) ) { // echo "$k: $v <br />\n"; //} $rpt_type = RepeatType($Entry['Repeat']['Interval']); $freq = $Entry['Repeat']['Frequency'] ? $Entry['Repeat']['Frequency'] : 1; if (strlen($Entry['Repeat']['EndTime'])) { $REND = localtime($Entry['Repeat']['EndTime']); $end = sprintf("%04d%02d%02d", $REND[5] + 1900, $REND[4] + 1, $REND[3]); } else { $end = 'NULL'; } $days = !empty($Entry['Repeat']['RepeatDays']) ? "'" . $Entry['Repeat']['RepeatDays'] . "'" : 'NULL'; $sql = "INSERT INTO webcal_entry_repeats ( cal_id, " . "cal_type, cal_end, cal_days, cal_frequency ) VALUES " . "( {$id}, '{$rpt_type}', {$end}, {$days}, {$freq} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = "Unable to add to webcal_entry_repeats: " . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } // Repeating Exceptions... if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_date = date("Ymd", $ex_date); $sql = "INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date ) VALUES ( {$id}, {$ex_date} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = "Unable to add to webcal_entry_repeats_not: " . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } } // End Repeat // Add Alarm info -> site_extras if ($updateMode) { dbi_query("DELETE FROM webcal_site_extras WHERE cal_id = {$id}"); } if ($Entry['AlarmSet'] == 1) { $RM = $Entry['AlarmAdvanceAmount']; if ($Entry['AlarmAdvanceType'] == 1) { $RM = $RM * 60; } if ($Entry['AlarmAdvanceType'] == 2) { $RM = $RM * 60 * 24; } $sql = "INSERT INTO webcal_site_extras ( cal_id, " . "cal_name, cal_type, cal_remind, cal_data ) VALUES " . "( {$id}, 'Reminder', 7, 1, {$RM} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); } } } if (!empty($error) && empty($overlap)) { $error_num++; echo "<h2>" . translate("Error") . "</h2>\n<blockquote>\n"; echo $error . "</blockquote>\n<br />\n"; } // Conflicting if (!empty($overlap)) { echo "<b><h2>" . translate("Scheduling Conflict") . ": "; $count_con++; echo "</h2></b>"; if ($Entry['Duration'] > 0) { $time = display_time($Entry['StartHour'] . $Entry['StartMinute'] . "00") . " - " . display_time($Entry['EndHour'] . $Entry['EndMinute'] . "00"); } $dd = $Entry['StartMonth'] . "-" . $Entry['StartDay'] . "-" . $Entry['StartYear']; echo "<a class=\"entry\" href=\"view_entry.php?id={$id}"; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; return true;\" onmouseout=\"window.status=''; return true;\">"; $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); echo htmlspecialchars($Entry['Summary']); echo "</a> (" . $dd; $time = trim($time); if (!empty($time)) { echo " " . $time; } echo ")<br />\n"; etranslate("conflicts with the following existing calendar entries"); echo ":<ul>\n" . $overlap . "</ul>\n"; } else { // No Conflict echo "<b><h2>" . translate("Event Imported") . ":</h2></b>\n"; $count_suc++; if ($Entry['Duration'] > 0) { $time = display_time($Entry['StartHour'] . $Entry['StartMinute'] . "00") . " - " . display_time($Entry['EndHour'] . $Entry['EndMinute'] . "00"); } $dateYmd = sprintf("%04d%02d%02d", $Entry['StartYear'], $Entry['StartMonth'], $Entry['StartDay']); $dd = date_to_str($dateYmd); echo "<a class=\"entry\" href=\"view_entry.php?id={$id}"; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; return true;\" onmouseout=\"window.status=''; return true;\">"; $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\", "", $Entry['Summary']); echo htmlspecialchars($Entry['Summary']); echo "</a> (" . $dd; if (!empty($time)) { echo " " . $time; } echo ")<br />\n"; } // Reset Variables $overlap = $error = $dd = $time = ''; } // Mark old events from prior import as deleted. if ($overwrite && count($oldUIDs) > 0) { // We could do this with a single SQL using sub-select, but // I'm pretty sure MySQL does not support it. $old = array_keys($oldUIDs); for ($i = 0; $i < count($old); $i++) { $sql = "SELECT cal_id FROM webcal_import_data WHERE " . "cal_import_type = '{$type}' AND " . "cal_external_id = '{$old[$i]}' AND " . "cal_login = '******' AND " . "cal_id < {$firstEventId}"; $res = dbi_query($sql); if ($res) { while ($row = dbi_fetch_row($res)) { $oldIds[] = $row[0]; } dbi_free_result($res); } else { echo translate("Database error") . ": " . dbi_error() . "<br />\n"; } } for ($i = 0; $i < count($oldIds); $i++) { $sql = "UPDATE webcal_entry_user SET cal_status = 'D' " . "WHERE cal_id = {$oldIds[$i]}"; $sqlLog .= $sql . "<br />\n"; dbi_query($sql); $numDeleted++; } } //echo "<b>SQL:</b><br />\n$sqlLog\n"; }
} // Load exception days... but not for a new event (which can't have // exception dates yet) $ex_days = array(); if (!empty($id)) { $res = dbi_query("SELECT cal_date FROM webcal_entry_repeats_not " . "WHERE cal_id = {$id}"); if ($res) { while ($row = dbi_fetch_row($res)) { $ex_days[] = $row[0]; } dbi_free_result($res); } else { $error = translate("Database error") . ": " . dbi_error(); } } $dates = get_all_dates($date, $rpt_type, $endt, $dayst, $ex_days, $rpt_freq); $conflicts = check_for_conflicts($dates, $duration, $hour, $minute, $participants, $login, empty($id) ? 0 : $id); } if (empty($error) && !empty($conflicts)) { $error = translate("The following conflicts with the suggested time") . ": <ul>{$conflicts}</ul>"; } //Avoid Undefined variable message $msg = ''; if (empty($error)) { $newevent = true; // now add the entries if (empty($id) || $do_override) { $res = dbi_query("SELECT MAX(cal_id) FROM webcal_entry"); if ($res) { $row = dbi_fetch_row($res); $id = $row[0] + 1;
} if (empty($rpt_type)) { $rpt_type = ''; } if (empty($wkst)) { $wkst = 'MO'; } // First check for any schedule conflicts. if (empty($ALLOW_CONFLICT_OVERRIDE) || $ALLOW_CONFLICT_OVERRIDE != 'Y') { $confirm_conflicts = ''; } // Security precaution. if ($ALLOW_CONFLICTS != 'Y' && empty($confirm_conflicts) && strlen($entry_hour) > 0 && $timetype != 'U' && $eType != 'task') { $conf_until = empty($rpt_until) ? '' : $rpt_until; $conf_count = empty($count) ? 999 : $count; $dates = get_all_dates($eventstart, $rpt_type, $rpt_freq, array($bymonth, $byweekno, $byyearday, $bymonthday, $byday, $bysetpos), $conf_count, $conf_until, $wkst, $exception_list, $inclusion_list); // Make sure at least start date is in array. if (empty($dates)) { $dates[0] = $eventstart; } // Make sure $thismonth and $thisyear are set for use in query_events (). $thismonth = $month; $thisyear = $year; $conflicts = check_for_conflicts($dates, $duration, $eventstart, $participants, $login, empty($id) ? 0 : $id); } //end check for any schedule conflicts if (empty($error) && !empty($conflicts)) { $error = translate('The following conflicts with the suggested time') . ': <ul>$conflicts</ul>'; } $msg = ''; if (empty($error)) {
function query_events($user, $want_repeated, $date_filter, $cat_id = '', $is_task = false) { global $db_connection_info, $jumpdate, $layers, $login, $max_until, $PUBLIC_ACCESS_DEFAULT_VISIBLE, $result, $thismonth, $thisyear; global $OVERRIDE_PUBLIC, $OVERRIDE_PUBLIC_TEXT; // New multiple categories requires some checking to see if this cat_id is // valid for this cal_id. It could be done with nested SQL, // but that may not work for all databases. This might be quicker also. $catlist = $cloneRepeats = $layers_byuser = $result = array(); $sql = 'SELECT DISTINCT( cal_id ) FROM webcal_entry_categories '; // None was selected...return only events without categories. if ($cat_id == -1) { $rows = dbi_get_cached_rows($sql, array()); } elseif (!empty($cat_id)) { $cat_array = explode(',', $cat_id); $placeholders = ''; for ($p_i = 0, $cnt = count($cat_array); $p_i < $cnt; $p_i++) { $placeholders .= $p_i == 0 ? '?' : ', ?'; } $rows = dbi_get_cached_rows($sql . 'WHERE cat_id IN ( ' . $placeholders . ' )', $cat_array); } if (!empty($cat_id)) { // $rows = dbi_get_cached_rows ( $sql, array ( $cat_id ) ); if ($rows) { for ($i = 0, $cnt = count($rows); $i < $cnt; $i++) { $row = $rows[$i]; $catlist[$i] = $row[0]; } } } $catlistcnt = count($catlist); $query_params = array(); $sql = 'SELECT we.cal_name, we.cal_description, we.cal_date, we.cal_time, we.cal_id, we.cal_ext_for_id, we.cal_priority, we.cal_access, we.cal_duration, weu.cal_status, we.cal_create_by, weu.cal_login, we.cal_type, we.cal_location, we.cal_url, we.cal_due_date, we.cal_due_time, weu.cal_percent, we.cal_mod_date, we.cal_mod_time ' . ($want_repeated ? ', wer.cal_type, wer.cal_end, wer.cal_frequency, wer.cal_days, wer.cal_bymonth, wer.cal_bymonthday, wer.cal_byday, wer.cal_bysetpos, wer.cal_byweekno, wer.cal_byyearday, wer.cal_wkst, wer.cal_count, wer.cal_endtime FROM webcal_entry we, webcal_entry_repeats wer, webcal_entry_user weu WHERE we.cal_id = wer.cal_id AND ' : 'FROM webcal_entry we, webcal_entry_user weu WHERE ') . 'we.cal_id = weu.cal_id AND weu.cal_status IN ( \'A\',\'W\' ) '; if ($catlistcnt > 0) { $placeholders = ''; for ($p_i = 0; $p_i < $catlistcnt; $p_i++) { $placeholders .= $p_i == 0 ? '?' : ', ?'; $query_params[] = $catlist[$p_i]; } if ($cat_id > 0) { $sql .= 'AND we.cal_id IN ( ' . $placeholders . ' ) '; } elseif ($cat_id == -1) { // Eliminate events with categories. $sql .= 'AND we.cal_id NOT IN ( ' . $placeholders . ' ) '; } } else { if (!empty($cat_id)) { // Force no rows to be returned. No matching entries in category. $sql .= 'AND 1 = 0 '; } } $sql .= 'AND we.cal_type IN ' . ($is_task == false ? '( \'E\',\'M\' ) ' : '( \'N\',\'T\' ) AND ( we.cal_completed IS NULL ) ') . (strlen($user) > 0 ? 'AND ( weu.cal_login = ? ' : ''); $query_params[] = $user; if ($user == $login && strlen($user) > 0 && $layers) { foreach ($layers as $layer) { $layeruser = $layer['cal_layeruser']; $sql .= 'OR weu.cal_login = ? '; $query_params[] = $layeruser; // While we are parsing the whole layers array, build ourselves // a new array that will help when we have to check for dups. $layers_byuser[$layeruser] = $layer['cal_dups']; } } $rows = dbi_get_cached_rows($sql . ($user == $login && strlen($user) && $PUBLIC_ACCESS_DEFAULT_VISIBLE == 'Y' ? 'OR weu.cal_login = \'__public__\' ' : '') . (strlen($user) > 0 ? ') ' : '') . $date_filter . (!$is_task ? ' ORDER BY we.cal_time, we.cal_name' : ''), $query_params); if ($rows) { $i = 0; $checkdup_id = $first_i_this_id = -1; for ($ii = 0, $cnt = count($rows); $ii < $cnt; $ii++) { $row = $rows[$ii]; if ($row[9] == 'D' || $row[9] == 'R') { continue; } // Don't show deleted/rejected ones. // Get primary category for this event, used for icon and color. $categories = get_categories_by_id($row[4], $user); $cat_keys = array_keys($categories); $primary_cat = empty($cat_keys[0]) ? '' : $cat_keys[0]; if ($login == '__public__' && !empty($OVERRIDE_PUBLIC) && $OVERRIDE_PUBLIC == 'Y') { $evt_name = $OVERRIDE_PUBLIC_TEXT; $evt_descr = $OVERRIDE_PUBLIC_TEXT; } else { $evt_name = $row[0]; $evt_descr = $row[1]; } if ($want_repeated && !empty($row[20])) { // row[20] = cal_type $item = new RepeatingEvent($evt_name, $evt_descr, $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $primary_cat, $row[11], $row[12], $row[13], $row[14], $row[15], $row[16], $row[17], $row[18], $row[19], $row[20], $row[21], $row[22], $row[23], $row[24], $row[25], $row[26], $row[27], $row[28], $row[29], $row[30], $row[31], $row[32], array(), array(), array()); } else { $item = new Event($evt_name, $evt_descr, $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $primary_cat, $row[11], $row[12], $row[13], $row[14], $row[15], $row[16], $row[17], $row[18], $row[19]); } if ($item->getID() != $checkdup_id) { $checkdup_id = $item->getID(); $first_i_this_id = $i; } if ($item->getLogin() == $user) { // Insert this one before all other ones with this ID. array_splice($result, $first_i_this_id, 0, array($item)); $i++; if ($first_i_this_id + 1 < $i) { // There's another one with the same ID as the one we inserted. // Check for dup and if so, delete it. $other_item = $result[$first_i_this_id + 1]; if (!empty($layers_byuser[$other_item->getLogin()]) && $layers_byuser[$other_item->getLogin()] == 'N') { // NOTE: array_splice requires PHP4 array_splice($result, $first_i_this_id + 1, 1); $i--; } } } else { if ($i == $first_i_this_id || !empty($layers_byuser[$item->getLogin()]) && $layers_byuser[$item->getLogin()] != 'N') { // This item either is the first one with its ID, or allows dups. // Add it to the end of the array. $result[$i++] = $item; } } // Does event go past midnight? if (date('Ymd', $item->getDateTimeTS()) != date('Ymd', $item->getEndDateTimeTS()) && !$item->isAllDay() && $item->getCalTypeName() == 'event') { getOverLap($item, $i, true); $i = count($result); } } } if ($want_repeated) { // Now load event exceptions/inclusions and store as array. // TODO: Allow passing this max_until as param in case we create // a custom report that shows N years of events. if (empty($max_until)) { $max_until = mktime(0, 0, 0, $thismonth + 2, 1, $thisyear); } for ($i = 0, $resultcnt = count($result); $i < $resultcnt; $i++) { if ($result[$i]->getID() != '') { $rows = dbi_get_cached_rows('SELECT cal_date, cal_exdate FROM webcal_entry_repeats_not WHERE cal_id = ?', array($result[$i]->getID())); for ($ii = 0, $rowcnt = count($rows); $ii < $rowcnt; $ii++) { $row = $rows[$ii]; // If this is not a clone, add exception date. if (!$result[$i]->getClone()) { $except_date = $row[0]; } if ($row[1] == 1) { $result[$i]->addRepeatException($except_date, $result[$i]->getID()); } else { $result[$i]->addRepeatInclusion($except_date); } } // Get all dates for this event. // If clone, we'll get the dates from parent later. if (!$result[$i]->getClone()) { $until = $result[$i]->getRepeatEndDateTimeTS() ? $result[$i]->getRepeatEndDateTimeTS() : $max_until; // Try to minimize the repeat search by shortening // until if BySetPos is not used. if (!$result[$i]->getRepeatBySetPos() && $until > $max_until) { $until = $max_until; } $rpt_count = 999; //Some BIG number. // End date... for year view and some reports we need whole year... // So, let's do up to 365 days after current month. // TODO: Add this end time as a parameter in case someone creates // a custom report that asks for N years of events. // $jump = mktime ( 0, 0, 0, $thismonth -1, 1, $thisyear); if ($result[$i]->getRepeatCount()) { $rpt_count = $result[$i]->getRepeatCount() - 1; } $date = $result[$i]->getDateTimeTS(); if ($result[$i]->isAllDay() || $result[$i]->isUntimed()) { $date += 43200; } //A simple hack to prevent DST problems. // TODO get this to work // C heck if this event id has been cached. // $file = ''; // if ( ! empty ( $db_connection_info['cachedir'] ) ){ // $hash = md5 ( $result[$i]->getId () . $until . $jump ); // $file = $db_connection_info['cachedir'] . '/' . $hash . '.dat'; // } // if ( file_exists ( $file ) ) { // $dates = unserialize ( file_get_contents ( $file ) ); // } else { $dates = get_all_dates($date, $result[$i]->getRepeatType(), $result[$i]->getRepeatFrequency(), array($result[$i]->getRepeatByMonth(), $result[$i]->getRepeatByWeekNo(), $result[$i]->getRepeatByYearDay(), $result[$i]->getRepeatByMonthDay(), $result[$i]->getRepeatByDay(), $result[$i]->getRepeatBySetPos()), $rpt_count, $until, $result[$i]->getRepeatWkst(), $result[$i]->getRepeatExceptions(), $result[$i]->getRepeatInclusions(), $jumpdate); $result[$i]->addRepeatAllDates($dates); // Serialize and save in cache for later use. // if ( ! empty ( $db_connection_info['cachedir'] ) ) { // $fd = @fopen ( $file, 'w+b', false ); // if ( empty ( $fd ) ) { // dbi_fatal_error ( "Cache error: could not write file $file" ); // } // fwrite ( $fd, serialize ( $dates ) ); // fclose ( $fd ); // chmod ( $file, 0666 ); // } // } } else { // Process clones if any. if (count($result[$i - 1]->getRepeatAllDates()) > 0) { $parentRepeats = $result[$i - 1]->getRepeatAllDates(); $cloneRepeats = array(); for ($j = 0, $parentRepeatscnt = count($parentRepeats); $j < $parentRepeatscnt; $j++) { $cloneRepeats[] = gmdate('Ymd', date_to_epoch($parentRepeats[$j]) + ONE_DAY); } $result[$i]->addRepeatAllDates($cloneRepeats); } } } } } return $result; }
function lcs_import_data($data, $overwrite, $type) { global $login, $count_con, $count_suc, $error_num, $ImportType; global $single_user, $single_user_login, $numDeleted, $errormsg; global $ALLOW_CONFLICTS, $ALLOW_CONFLICT_OVERRIDE, $H2COLOR; global $calUser, $sqlLog, $message; $oldUIDs = array(); $oldIds = array(); $firstEventId = $count_suc = 0; $ImportType = 'ICAL'; // $importId = -1; $importId = 1; $subType = ''; if ($type == 'icalclient') { $ImportType = 'ICAL'; $type = 'ical'; $subType = 'icalclient'; } else { if ($type == 'remoteics' || $type == 'hcal') { $ImportType = 'RMTICS'; $type = 'rmtics'; $subType = 'remoteics'; } } if ($overwrite) { //on efface tous les evenement edt du user //recherche du cat_id $res = dbi_execute('SELECT cat_id FROM webcal_categories WHERE cat_owner = ? AND cat_name = ?', array($login, 'EDT')); if ($res) { if ($row = dbi_fetch_row($res)) { $id_cat = $row[0]; } dbi_free_result($res); } //recherche des cal_id $res = dbi_execute('SELECT cal_id FROM webcal_entry_categories WHERE cat_id = ' . $id_cat); if ($res) { $i = 0; while ($row = dbi_fetch_row($res)) { $id_cals[$i] = $row[0]; $i++; } dbi_free_result($res); } $message .= 'Evénements supprimés : ' . count($id_cals) . '<br />'; if (isset($id_cals)) { foreach ($id_cals as $id_cals) { // Delete event for this user dbi_execute('DELETE FROM webcal_entry WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_entry_user WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_import_data WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_entry_log WHERE cal_entry_id = ?', array($id_cals)); } } dbi_execute('DELETE FROM webcal_entry_categories WHERE cat_id = ' . $id_cat); } // Generate a unique import id $res = dbi_execute('SELECT MAX(cal_import_id) FROM webcal_import'); if ($res) { if ($row = dbi_fetch_row($res)) { $importId = $row[0] + 1; } dbi_free_result($res); } $sql = 'INSERT INTO webcal_import ( cal_import_id, cal_name, cal_date, cal_type, cal_login ) VALUES ( ?, NULL, ?, ?, ? )'; if (!dbi_execute($sql, array($importId, date('Ymd'), $type, $login))) { $errormsg = db_error(); $my_errormsg .= db_error(); return; } if (!is_array($data)) { return false; } foreach ($data as $Entry) { // do_debug ( "Entry Array " . print_r ( $Entry, true ) ); $participants[0] = $calUser; // $participants[0] = $login; $Entry['start_date'] = gmdate('Ymd', $Entry['StartTime']); $Entry['start_time'] = gmdate('His', $Entry['StartTime']); $Entry['end_date'] = gmdate('Ymd', $Entry['EndTime']); $Entry['end_time'] = gmdate('His', $Entry['EndTime']); // not in icalclient if ($overwrite && !empty($Entry['UID'])) { if (empty($oldUIDs[$Entry['UID']])) { $oldUIDs[$Entry['UID']] = 1; } else { $oldUIDs[$Entry['UID']]++; } } // Check for untimed if (!empty($Entry['Untimed']) && $Entry['Untimed'] == 1) { $Entry['start_time'] = 0; } // Check for all day if (!empty($Entry['AllDay']) && $Entry['AllDay'] == 1) { $Entry['start_time'] = 0; $Entry['end_time'] = 0; $Entry['Duration'] = '1440'; } $priority = !empty($Entry['Priority']) ? $Entry['Priority'] : 5; if (!empty($Entry['Completed'])) { $cal_completed = substr($Entry['Completed'], 0, 8); } else { $cal_completed = ''; } if (strlen($cal_completed < 8)) { $cal_completed = ''; } $months = !empty($Entry['Repeat']['ByMonth']) ? $Entry['Repeat']['ByMonth'] : ''; $updateMode = false; // See if event already is there from prior import. // The same UID is used for all events imported at once with iCal. // So, we still don't have enough info to find the exact // event we want to replace. We could just delete all // existing events that correspond to the UID. // NOTE:(cek) commented out 'publish'. Will not work if event // was originally created from importing. if (!empty($Entry['UID'])) { $res = dbi_execute('SELECT wid.cal_id ' . 'FROM webcal_import_data wid, webcal_entry_user weu WHERE ' . 'wid.cal_id = weu.cal_id AND ' . 'weu.cal_login = ? AND ' . 'cal_external_id = ?', array($login, $Entry['UID'])); if ($res) { if ($row = dbi_fetch_row($res)) { if (!empty($row[0])) { $id = $row[0]; $updateMode = true; // update rather than add a new event } } } } if (!$updateMode && $subType != 'icalclient' && $subType != 'remoteics') { // first check for any schedule conflicts if ($ALLOW_CONFLICT_OVERRIDE == 'N' && $ALLOW_CONFLICTS == 'N' && $Entry['Duration'] != 0) { $ex_days = array(); if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_days[] = gmdate('Ymd', $ex_date); } } $inc_days = array(); if (!empty($Entry['Repeat']['Inclusions'])) { foreach ($Entry['Repeat']['Inclusions'] as $inc_date) { $inc_days[] = gmdate('Ymd', $inc_date); } } // test if all Repeat Elements exist $rep_interval = !empty($Entry['Repeat']['Interval']) ? $Entry['Repeat']['Interval'] : ''; $rep_bymonth = !empty($Entry['Repeat']['ByMonth']) ? $Entry['Repeat']['ByMonth'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byyearday = !empty($Entry['Repeat']['ByYearDay']) ? $Entry['Repeat']['ByYearDay'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_bymonthday = !empty($Entry['Repeat']['ByMonthDay']) ? $Entry['Repeat']['ByMonthDay'] : ''; $rep_byday = !empty($Entry['Repeat']['ByDay']) ? $Entry['Repeat']['ByDay'] : ''; $rep_bysetpos = !empty($Entry['Repeat']['BySetPos']) ? $Entry['Repeat']['BySetPos'] : ''; $rep_count = !empty($Entry['Repeat']['Count']) ? $Entry['Repeat']['Count'] : ''; $rep_until = !empty($Entry['Repeat']['Until']) ? $Entry['Repeat']['Until'] : ''; $rep_wkst = !empty($Entry['Repeat']['Wkst']) ? $Entry['Repeat']['Wkst'] : ''; $dates = get_all_dates($Entry['StartTime'], RepeatType($Entry['Repeat']['Frequency']), $rep_interval, array($rep_bymonth, $rep_byweekno, $rep_byyearday, $rep_bymonthday, $rep_byday, $rep_bysetpos), $rep_count, $rep_until, $rep_wkst, $ex_days, $inc_days); $overlap = check_for_conflicts($dates, $Entry['Duration'], $Entry['StartTime'], $participants, $login, 0); } } //end $subType != 'icalclient' && != 'remoteics' if (empty($error)) { if (!$updateMode) { // Add the Event $res = dbi_execute('SELECT MAX(cal_id) FROM webcal_entry'); if ($res) { $row = dbi_fetch_row($res); $id = $row[0] + 1; dbi_free_result($res); } else { $id = 1; } } // not in icalclient if ($firstEventId == 0) { $firstEventId = $id; } $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = $id; if (!$updateMode) { $names[] = 'cal_create_by'; $values[] = $ImportType == 'RMTICS' ? $calUser : $login; } $names[] = 'cal_date'; $values[] = $Entry['start_date']; $names[] = 'cal_time'; $values[] = !empty($Entry['Untimed']) && $Entry['Untimed'] == 1 ? '-1' : $Entry['start_time']; $names[] = 'cal_mod_date'; $values[] = gmdate('Ymd'); $names[] = 'cal_mod_time'; $values[] = gmdate('Gis'); $names[] = 'cal_duration'; $values[] = sprintf("%d", $Entry['Duration']); $names[] = 'cal_priority'; $values[] = $priority; if (!empty($Entry['Class'])) { $names[] = 'cal_access'; $entryclass = $Entry['Class']; $values[] = $entryclass; } if (!empty($Entry['Location'])) { $names[] = 'cal_location'; $entryclass = $Entry['Location']; $values[] = $entryclass; } if (!empty($Entry['URL'])) { $names[] = 'cal_url'; $entryclass = $Entry['URL']; $values[] = $entryclass; } if (!empty($cal_completed)) { $names[] = 'cal_completed'; $values[] = $cal_completed; } if (!empty($Entry['Due'])) { $names[] = 'cal_due_date'; $values[] = sprintf("%d", substr($Entry['Due'], 0, 8)); $names[] = 'cal_due_time'; $values[] = sprintf("%d", substr($Entry['Due'], 9, 6)); } if (!empty($Entry['CalendarType'])) { $names[] = 'cal_type'; if ($Entry['CalendarType'] == 'VEVENT' || $Entry['CalendarType'] == 'VFREEBUSY') { $values[] = !empty($Entry['Repeat']) ? 'M' : 'E'; } else { if ($Entry['CalendarType'] == 'VTODO') { $values[] = !empty($Entry['Repeat']) ? 'N' : 'T'; } } } if (strlen($Entry['Summary']) == 0) { $Entry['Summary'] = translate('Unnamed Event'); } if (empty($Entry['Description'])) { $Entry['Description'] = $Entry['Summary']; } $Entry['Summary'] = str_replace("\\n", "\n", $Entry['Summary']); $Entry['Summary'] = str_replace("\\'", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\\"", "\"", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $names[] = 'cal_name'; $values[] = $Entry['Summary']; $Entry['Description'] = str_replace("\\n", "\n", $Entry['Description']); $Entry['Description'] = str_replace("\\'", "'", $Entry['Description']); $Entry['Description'] = str_replace("\\\"", "\"", $Entry['Description']); $Entry['Description'] = str_replace("'", "\\'", $Entry['Description']); // added these to try and compensate for Sunbird escaping html $Entry['Description'] = str_replace("\\;", ";", $Entry['Description']); $Entry['Description'] = str_replace("\\,", ",", $Entry['Description']); // Mozilla will send this goofy string, so replace it with real html $Entry['Description'] = str_replace('=0D=0A=', '<br />', $Entry['Description']); $Entry['Description'] = str_replace('=0D=0A', '', $Entry['Description']); // Allow option to not limit description size // This will only be practical for mysql and MSSQL/Postgres as // these do not have limits on the table definition // TODO Add this option to preferences if (empty($LIMIT_DESCRIPTION_SIZE) || $LIMIT_DESCRIPTION_SIZE == 'Y') { // limit length to 1024 chars since we setup tables that way if (strlen($Entry['Description']) >= 1024) { $Entry['Description'] = substr($Entry['Description'], 0, 1019) . '...'; } } $names[] = 'cal_description'; $values[] = $Entry['Description']; // do_debug ( "descr='" . $Entry['Description'] . "'" ); $sql_params = array(); $namecnt = count($names); if ($updateMode) { $sql = 'UPDATE webcal_entry SET '; for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $sql .= ', '; } $sql .= $names[$f] . ' = ?'; $sql_params[] = $values[$f]; } $sql .= ' WHERE cal_id = ?'; $sql_params[] = $id; } else { $string_names = ''; $string_values = ''; for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_entry ( ' . $string_names . ' ) VALUES ( ' . $string_values . ' )'; } //do_debug ( date("H:i:s")." entry SQL> $sql" ); if (empty($error)) { if (!dbi_execute($sql, $sql_params)) { $error .= db_error(); // do_debug ( $error ); break; } else { if ($ImportType == 'RMTICS') { $count_suc++; } } } // log add/update if ($Entry['CalendarType'] == 'VTODO') { activity_log($id, $login, $calUser, $updateMode ? LOG_UPDATE_T : LOG_CREATE_T, 'Import from ' . $ImportType); } else { activity_log($id, $login, $calUser, $updateMode ? LOG_UPDATE : LOG_CREATE, 'Import from ' . $ImportType); } // not in icalclient if ($single_user == 'Y') { $participants[0] = $single_user_login; } // Now add to webcal_import_data if (!$updateMode) { // only in icalclient // add entry to webcal_import and webcal_import_data $uid = generate_uid($id); $uid = empty($Entry['UID']) ? $uid : $Entry['UID']; if ($importId < 0) { $importId = create_import_instance(); } if ($ImportType == 'PALMDESKTOP') { $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'palm', $Entry['RecordID']))) { $error = db_error(); break; } } else { if ($ImportType == 'VCAL') { $uid = empty($Entry['UID']) ? null : $Entry['UID']; if (strlen($uid) > 200) { $uid = null; } $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'vcal', $uid))) { $error = db_error(); break; } } else { if ($ImportType == 'ICAL') { $uid = empty($Entry['UID']) ? null : $Entry['UID']; // This may cause problems if (strlen($uid) > 200) { $uid = substr($uid, 0, 200); } $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'ical', $uid))) { $error = db_error(); break; } } } } } // Now add participants $status = !empty($Entry['Status']) ? $Entry['Status'] : 'A'; $percent = !empty($Entry['Percent']) ? $Entry['Percent'] : '0'; if (!$updateMode) { $sql = 'INSERT INTO webcal_entry_user ( cal_id, cal_login, cal_status, cal_percent ) VALUES ( ?, ?, ?, ? )'; //( date("H:i:s")."add part SQL> $sql" ); if (!dbi_execute($sql, array($id, $participants[0], $status, $percent))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } else { // ( date("H:i:s")." up part SQL> $sql" ); $sql = 'UPDATE webcal_entry_user SET cal_status = ? WHERE cal_id = ?'; if (!dbi_execute($sql, array($status, $id))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } // update percentage only if set if ($percent != '') { $sql = 'UPDATE webcal_entry_user SET cal_percent = ? WHERE cal_id = ?'; if (!dbi_execute($sql, array($percent, $id))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } dbi_execute('DELETE FROM webcal_entry_categories WHERE cal_id = ?', array($id)); } // update Categories if (!empty($Entry['Categories'])) { $cat_ids = $Entry['Categories']; $cat_order = 1; foreach ($cat_ids as $cat_id) { $sql = 'INSERT INTO webcal_entry_categories ( cal_id, cat_id, cat_order, cat_owner ) VALUES ( ?, ?, ?, ? )'; if (!dbi_execute($sql, array($id, $cat_id, $cat_order++, $login))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } } // Add repeating info if ($updateMode) { // remove old repeating info dbi_execute('DELETE FROM webcal_entry_repeats WHERE cal_id = ?', array($id)); dbi_execute('DELETE FROM webcal_entry_repeats_not WHERE cal_id = ?', array($id)); } $names = array(); $values = array(); if (!empty($Entry['Repeat']['Frequency'])) { $names[] = 'cal_id'; $values[] = $id; $names[] = 'cal_type'; $values[] = RepeatType($Entry['Repeat']['Frequency']); $names[] = 'cal_frequency'; $values[] = !empty($Entry['Repeat']['Interval']) ? $Entry['Repeat']['Interval'] : 1; if (!empty($Entry['Repeat']['ByMonth'])) { $names[] = 'cal_bymonth'; $values[] = $Entry['Repeat']['ByMonth']; } if (!empty($Entry['Repeat']['ByMonthDay'])) { $names[] = 'cal_bymonthday'; $values[] = $Entry['Repeat']['ByMonthDay']; } if (!empty($Entry['Repeat']['ByDay'])) { $names[] = 'cal_byday'; $values[] = $Entry['Repeat']['ByDay']; } if (!empty($Entry['Repeat']['BySetPos'])) { $names[] = 'cal_bysetpos'; $values[] = $Entry['Repeat']['BySetPos']; } if (!empty($Entry['Repeat']['ByWeekNo'])) { $names[] = 'cal_byweekno'; $values[] = $Entry['Repeat']['ByWeekNo']; } if (!empty($Entry['Repeat']['ByYearDay'])) { $names[] = 'cal_byyearday'; $values[] = $Entry['Repeat']['ByYearDay']; } if (!empty($Entry['Repeat']['Wkst'])) { $names[] = 'cal_wkst'; $values[] = $Entry['Repeat']['Wkst']; } if (!empty($Entry['Repeat']['Count'])) { $names[] = 'cal_count'; $values[] = $Entry['Repeat']['Count']; } if (!empty($Entry['Repeat']['Until'])) { $REND = localtime($Entry['Repeat']['Until']); if (!empty($Entry['Repeat']['Count'])) { // Get end time from DTSTART $RENDTIME = $Entry['start_time']; } else { $RENDTIME = gmdate('His', $Entry['Repeat']['Until']); } $names[] = 'cal_end'; $values[] = gmdate('Ymd', $Entry['Repeat']['Until']); // if ( $RENDTIME != '000000' ) { $names[] = 'cal_endtime'; $values[] = $RENDTIME; // } } $string_names = ''; $string_values = ''; $sql_params = array(); $namecnt = count($names); for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_entry_repeats ( ' . $string_names . ' ) VALUES ( ' . $string_values . ' )'; if (!dbi_execute($sql, $sql_params)) { $error = 'Unable to add to webcal_entry_repeats: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } // Repeating Exceptions... if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_date = gmdate('Ymd', $ex_date); $sql = 'INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?,?,? )'; if (!dbi_execute($sql, array($id, $ex_date, 1))) { $error = 'Unable to add to webcal_entry_repeats_not: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } // Repeating Inclusions... if (!empty($Entry['Repeat']['Inclusions'])) { foreach ($Entry['Repeat']['Inclusions'] as $inc_date) { $inc_date = gmdate('Ymd', $inc_date); $sql = 'INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?,?,? )'; if (!dbi_execute($sql, array($id, $inc_date, 0))) { $error = 'Unable to add to webcal_entry_repeats_not: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } } // End Repeat // Add Alarm info if ($updateMode) { dbi_execute('DELETE FROM webcal_reminders WHERE cal_id = ?', array($id)); } if (!empty($Entry['AlarmSet']) && $Entry['AlarmSet'] == 1) { $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = $id; if (!empty($Entry['ADate'])) { $names[] = 'cal_date'; $values[] = $Entry['ADate']; } if (!empty($Entry['AOffset'])) { $names[] = 'cal_offset'; $values[] = $Entry['AOffset']; } if (!empty($Entry['ADuration'])) { $names[] = 'cal_duration'; $values[] = $Entry['ADuration']; } if (!empty($Entry['ARepeat'])) { $names[] = 'cal_repeats'; $values[] = $Entry['ARepeat']; } if (!empty($Entry['ABefore'])) { $names[] = 'cal_before'; $values[] = $Entry['ABefore']; } if (!empty($Entry['ARelated'])) { $names[] = 'cal_related'; $values[] = $Entry['ARelated']; } if (!empty($Entry['AAction'])) { $names[] = 'cal_action'; $values[] = $Entry['AAction']; } $string_names = ''; $string_values = ''; $sql_params = array(); $namecnt = count($names); for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_reminders (' . $string_names . ' ) ' . ' VALUES ( ' . $string_values . ' )'; if (!dbi_execute($sql, $sql_params)) { $error = db_error(); } } } // here to end not in icalclient if ($subType != 'icalclient' && $subType != 'remoteics') { if (!empty($error) && empty($overlap)) { $error_num++; echo print_error($error) . "\n<br />\n"; } if ($Entry['Duration'] > 0) { $time = trim(display_time('', 0, $Entry['StartTime']) . '-' . display_time('', 2, $Entry['EndTime'])); } // Conflicting if (!empty($overlap)) { $message .= '<b><h2>' . translate('Scheduling Conflict') . ': '; $count_con++; $message .= '</h2></b>'; $dd = date('m-d-Y', $Entry['StartTime']); $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $message .= htmlspecialchars($Entry['Summary']); $message .= ' (' . $dd; if (!empty($time)) { $message .= ' ' . $time; } $message .= ")<br />\n"; etranslate('conflicts with the following existing calendar entries'); $message .= ":<ul>\n" . $overlap . "</ul>\n"; } else { // No Conflict if ($count_suc == 0) { //echo '<b><h2>' . //translate ( 'Event Imported' ) . ":</h2></b><br />\n"; } $count_suc++; $dd = $Entry['start_date']; } // Reset Variables $overlap = $error = $dd = $time = ''; } } }