Ejemplo n.º 1
0
function multiply($course_1, $course_combos, $from, $to, $limit, $campus, $closed)
{
    $combined = array();
    $new_combos = array();
    $count = 0;
    #if 2-D array course_combos is empty fill it up with the
    #array course_1 making each element an array of its own
    if (empty($course_combos)) {
        for ($i = 0; $i < count($course_1); $i = $i + 1) {
            if (time_day_constraint($course_1[$i], $limit, $from, $to) == true) {
                if (campus_check($campus, $course_1[$i]) == true) {
                    if (closed_check($closed, $course_1[$i]) == true) {
                        array_push($new_combos, array($course_1[$i]));
                    }
                }
            }
        }
        $count = 1;
    } else {
        for ($i = 0; $i < count($course_combos); $i = $i + 1) {
            for ($j = 0; $j < count($course_1); $j = $j + 1) {
                #If there is no overlap between elements in the array
                #and the new element push it into the array
                if (overlap($course_combos[$i], $course_1[$j]) == false) {
                    if (time_day_constraint($course_1[$j], $limit, $from, $to) == true) {
                        if (campus_check($campus, $course_1[$j]) == true) {
                            if (closed_check($closed, $course_1[$j]) == true) {
                                array_push($new_combos, $course_combos[$i]);
                                array_push($new_combos[$count], $course_1[$j]);
                                $count = $count + 1;
                            }
                        }
                    }
                } else {
                    echo "OVERLAP!\n";
                }
            }
        }
    }
    if ($count != 0) {
        return $new_combos;
    } else {
        return $course_combos;
    }
}
Ejemplo n.º 2
0
function orderTree($idx)
{
    global $orders, $orderLen;
    $order = $orders[$idx];
    $maxSubDepth = 0;
    $subOrders = array();
    $next_idx = $idx + 1;
    while ($next_idx < $orderLen) {
        if (overlap($orders[$idx], $orders[$next_idx])) {
            $subTree = orderTree($next_idx);
            $maxSubDepth = max($maxSubDepth, $subTree->depth);
            $next_idx = $subTree->next_idx;
            $subOrders[] = $subTree;
        } else {
            break;
        }
    }
    $order->next_idx = $next_idx;
    $order->subOrders = $subOrders;
    $order->depth = $maxSubDepth + 1;
    return $order;
}
Ejemplo n.º 3
0
/**
 * Generates a list of valid courses using a recursive tree-traversing
 * algorithm. This also prunes any branches of the tree that are invalid.
 * @param	array	$courseSet		The list of courses set up as an array of
 *									course slots, which are arrays of course
 *									information.
 * @param	array	$nonCourses		The list of nonCourse items that are fixed
 *									in the schedule
 * @param	array	$noCourses		The list of times when the user does not
 *									want courses
 * @param	array	$chain			A partially built schedule. Basically the
 *									parent list of the tree traversal
 * @param	array	$results		The list of complete and valid schedules
 * @param	int		$level			What level of the tree we're currently at
 * @return	array	Returns an array of complete and valid schedules
 */
function generateSchedules($courses, $nonCourses, $noCourses, $chain = array(), $results = array(), $level = 0)
{
    // Pull in the noncourses and nocourses
    global $NONCOURSES, $NOCOURSES;
    // Iterate over the course choices in the level
    $oldChain = $chain;
    // Use this to preserve the chain to eliminate multiple sections in same schedule
    foreach ($courses[$level] as $childCourse) {
        if (!overlap($chain, $childCourse) && !overlapNonCourse($nonCourses, $childCourse) && !overlapNoCourse($noCourses, $childCourse)) {
            // It doesn't overlap, so add it to the chain
            $chain[] = $childCourse;
            // If there are further children, recurse through them.
            if ($level < count($courses) - 1) {
                $results = generateSchedules($courses, $nonCourses, $noCourses, $chain, $results, $level + 1);
            } else {
                // The schedule is complete and valid!
                $results[] = $chain;
            }
        }
        // Replace the chain
        $chain = $oldChain;
    }
    return $results;
}
Ejemplo n.º 4
0
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 "&nbsp; " . $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 "&nbsp; " . $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";
}
Ejemplo n.º 5
0
function main()
{
    $query = '';
    if (isset($_GET['q'])) {
        $query = $_GET['q'];
        overlap($query);
    } else {
        display_form();
    }
}
Ejemplo n.º 6
0
     $eMsg .= $xx['evt_eml_list_missing'] . "<br>";
     break;
 }
 if (strlen($nml) > 255) {
     $eMsg .= $xx['evt_eml_list_too_long'] . "<br>";
     break;
 }
 if ($nol) {
     if ($r_t) {
         $eMsg .= $xx['evt_no_recur_if_overlay'] . "<br>";
         break;
     }
     if ($pri) {
         $wMsg .= $xx['evt_private_no_ovl_check'] . "<br>";
     }
     if (overlap($eid, $cid, $sDate, $eDate, $sTime, $eTime)) {
         $eMsg .= $oem . "<br>";
         break;
     }
 }
 //notify now
 if ($non) {
     $evtArr = array('cnm' => $cnm, 'ven' => $ven, 'des' => $desHtml, 'xf1' => $xf1Html, 'xf2' => $xf2Html);
     //Html: with hyperlinks
     notifyNow($evtArr, $mode);
 }
 //update database
 //if owner changed, default notMail = owner email
 if ($uid != $oUid) {
     $stH = stPrep("SELECT `email` FROM `users` WHERE `ID` = ?");
     stExec($stH, array($uid));