예제 #1
0
function check_for_conflicts($dates, $duration, $hour, $minute, $participants, $login, $id)
{
    global $single_user_login, $single_user;
    global $repeated_events, $limit_appts, $limit_appts_number;
    if (!count($dates)) {
        return false;
    }
    $evtcnt = array();
    $sql = "SELECT distinct webcal_entry_user.cal_login, webcal_entry.cal_time," . "webcal_entry.cal_duration, webcal_entry.cal_name, " . "webcal_entry.cal_id, webcal_entry.cal_ext_for_id, " . "webcal_entry.cal_access, " . "webcal_entry_user.cal_status, webcal_entry.cal_date " . "FROM webcal_entry, webcal_entry_user " . "WHERE webcal_entry.cal_id = webcal_entry_user.cal_id " . "AND (";
    for ($x = 0; $x < count($dates); $x++) {
        if ($x != 0) {
            $sql .= " OR ";
        }
        $sql .= "webcal_entry.cal_date = " . date("Ymd", $dates[$x]);
    }
    $sql .= ") AND webcal_entry.cal_time >= 0 " . "AND webcal_entry_user.cal_status IN ('A','W') AND ( ";
    if ($single_user == "Y") {
        $participants[0] = $single_user_login;
    } else {
        if (strlen($participants[0]) == 0) {
            // likely called from a form with 1 user
            $participants[0] = $login;
        }
    }
    for ($i = 0; $i < count($participants); $i++) {
        if ($i > 0) {
            $sql .= " OR ";
        }
        $sql .= " webcal_entry_user.cal_login = '******'";
    }
    $sql .= " )";
    // make sure we don't get something past the end date of the
    // event we are saving.
    //echo "SQL: $sql<P>";
    $conflicts = "";
    $res = dbi_query($sql);
    $found = array();
    $count = 0;
    if ($res) {
        $time1 = sprintf("%d%02d00", $hour, $minute);
        $duration1 = sprintf("%d", $duration);
        while ($row = dbi_fetch_row($res)) {
            //Add to an array to see if it has been found already for the next part.
            $found[$count++] = $row[4];
            // see if either event overlaps one another
            if ($row[4] != $id && (empty($row[5]) || $row[5] != $id)) {
                $time2 = $row[1];
                $duration2 = $row[2];
                $cntkey = $user . "-" . $row[8];
                $evtcnt[$cntkey]++;
                $over_limit = 0;
                if ($limit_appts == "Y" && $limit_appts_number > 0 && $evtcnt[$cntkey] >= $limit_appts_number) {
                    $over_limit = 1;
                }
                if ($over_limit || times_overlap($time1, $duration1, $time2, $duration2)) {
                    $conflicts .= "<LI>";
                    if ($single_user == "Y") {
                        $conflicts .= "{$row['0']}: ";
                    }
                    if ($row[6] == 'R' && $row[0] != $login) {
                        $conflicts .= "(" . translate("Private") . ")";
                    } else {
                        $conflicts .= "<A HREF=\"view_entry.php?id={$row['4']}";
                        if ($user != $login) {
                            $conflicts .= "&user={$user}";
                        }
                        $conflicts .= "\">{$row['3']}</A>";
                    }
                    if ($duration2 == 24 * 60) {
                        $conflicts .= " (" . translate("All day event") . ")";
                    } else {
                        $conflicts .= " (" . display_time($time2);
                        if ($duration2 > 0) {
                            $conflicts .= "-" . display_time(add_duration($time2, $duration2));
                        }
                        $conflicts .= ")";
                    }
                    $conflicts .= " on " . date_to_str($row[8]);
                    if ($over_limit) {
                        $tmp = translate("exceeds limit of XXX events per day");
                        $tmp = str_replace("XXX", $limit_appts_number, $tmp);
                        $conflicts .= " (" . $tmp . ")";
                    }
                }
            }
        }
        dbi_free_result($res);
    } else {
        echo translate("Database error") . ": " . dbi_error();
        exit;
    }
    //echo "<br>hello";
    for ($q = 0; $q < count($participants); $q++) {
        $time1 = sprintf("%d%02d00", $hour, $minute);
        $duration1 = sprintf("%d", $duration);
        //This date filter is not necessary for functional reasons, but it eliminates some of the
        //events that couldn't possibly match.  This could be made much more complex to put more
        //of the searching work onto the database server, or it could be dropped all together to put
        //the searching work onto the client.
        $date_filter = "AND (webcal_entry.cal_date <= " . date("Ymd", $dates[count($dates) - 1]);
        $date_filter .= " AND (webcal_entry_repeats.cal_end IS NULL OR webcal_entry_repeats.cal_end >= " . date("Ymd", $dates[0]) . "))";
        //Read repeated events for the participants only once for a participant for
        //for performance reasons.
        $repeated_events = query_events($participants[$q], true, $date_filter);
        //for ($dd=0; $dd<count($repeated_events); $dd++) {
        //  echo $repeated_events[$dd]['cal_id'] . "<BR>";
        //}
        for ($i = 0; $i < count($dates); $i++) {
            $dateYmd = date("Ymd", $dates[$i]);
            $list = get_repeating_entries($participants[$q], $dateYmd);
            $thisyear = substr($dateYmd, 0, 4);
            $thismonth = substr($dateYmd, 4, 2);
            for ($j = 0; $j < count($list); $j++) {
                //okay we've narrowed it down to a day, now I just gotta check the time...
                //I hope this is right...
                $row = $list[$j];
                if ($row['cal_id'] != $id && $row['cal_ext_for_id'] != $id) {
                    $time2 = $row['cal_time'];
                    $duration2 = $row['cal_duration'];
                    if (times_overlap($time1, $duration1, $time2, $duration2)) {
                        $conflicts .= "<LI>";
                        if ($single_user != "Y") {
                            $conflicts .= $row['cal_login'] . ": ";
                        }
                        if ($row['cal_access'] == 'R' && $row['cal_login'] != $login) {
                            $conflicts .= "(" . translate("Private") . ")";
                        } else {
                            $conflicts .= "<A HREF=\"view_entry.php?id=" . $row['cal_id'];
                            if ($user != $login) {
                                $conflicts .= "&user={$user}";
                            }
                            $conflicts .= "\">" . $row['cal_name'] . "</A>";
                        }
                        $conflicts .= " (" . display_time($time2);
                        if ($duration2 > 0) {
                            $conflicts .= "-" . display_time(add_duration($time2, $duration2));
                        }
                        $conflicts .= ")";
                        $conflicts .= " on " . date("l, F j, Y", $dates[$i]);
                    }
                }
            }
        }
    }
    return $conflicts;
}
예제 #2
0
            case "monthlyByDate":
                $rep_str .= translate("Month") . "/" . translate("by date");
                break;
            case "yearly":
                $rep_str .= translate("Year");
                break;
        }
        $rep_str .= ")";
    } else {
        $rep_str = "";
    }
    dbi_free_result($res);
}
/* calculate end time */
if ($event_time > 0 && $row[5] > 0) {
    $end_str = "-" . display_time(add_duration($row[2], $row[5]));
} else {
    $end_str = "";
}
// get the email adress of the creator of the entry
user_load_variables($create_by, "createby_");
$email_addr = $createby_email;
// If confidential and not this user's event, then
// They cannot seem name or description.
//if ( $row[8] == "R" && ! $is_my_event && ! $is_admin ) {
if ($row[8] == "R" && !$is_my_event) {
    $is_private = true;
    $name = "[" . translate("Confidential") . "]";
    $description = "[" . translate("Confidential") . "]";
} else {
    $is_private = false;
예제 #3
0
 function testAddDuration()
 {
     $this->assertEqual(add_duration('123456', '50'), '132400');
     $this->assertNotEqual(add_duration('123456', '1490'), '132400');
 }
예제 #4
0
    etranslate("Scheduling Conflict");
    ?>
</h2>

<?php 
    etranslate("Your suggested time of");
    ?>
 <span style="font-weight:bold;">
<?php 
    if (!empty($allday) && $allday == "Y") {
        etranslate("All day event");
    } else {
        $time = sprintf("%d%02d00", $hour, $minute);
        echo display_time($time);
        if ($duration > 0) {
            echo "-" . display_time(add_duration($time, $duration));
        }
    }
    ?>
</span> <?php 
    etranslate("conflicts with the following existing calendar entries");
    ?>
:
<ul>
<?php 
    echo $conflicts;
    ?>
</ul>

<?php 
    // user can confirm conflicts
function check_for_conflicts($dates, $duration, $eventstart, $participants, $login, $id)
{
    global $LIMIT_APPTS, $LIMIT_APPTS_NUMBER, $repeated_events, $single_user, $single_user_login, $jumpdate;
    $datecnt = count($dates);
    if (!$datecnt) {
        return false;
    }
    $conflicts = '';
    $count = 0;
    $evtcnt = $found = $query_params = array();
    $partcnt = count($participants);
    $hour = gmdate('H', $eventstart);
    $minute = gmdate('i', $eventstart);
    $allDayStr = translate('All day event');
    $confidentialStr = translate('Confidential');
    $exceedsStr = translate('exceeds limit of XXX events per day');
    $onStr = translate('on');
    $privateStr = translate('Private');
    $sql = 'SELECT DISTINCT( weu.cal_login ), we.cal_time, we.cal_duration,
    we.cal_name, we.cal_id, we.cal_access, weu.cal_status, we.cal_date
    FROM webcal_entry we, webcal_entry_user weu WHERE we.cal_id = weu.cal_id AND ( ';
    for ($i = 0; $i < $datecnt; $i++) {
        $sql .= ($i != 0 ? ' OR ' : '') . 'we.cal_date = ' . gmdate('Ymd', $dates[$i]);
    }
    $sql .= ' ) AND we.cal_time >= 0 AND weu.cal_status IN ( \'A\',\'W\' ) AND ( ';
    if ($single_user == 'Y') {
        $participants[0] = $single_user_login;
    } else {
        if (strlen($participants[0]) == 0) {
            // Likely called from a form with 1 user.
            $participants[0] = $login;
        }
    }
    for ($i = 0; $i < $partcnt; $i++) {
        $sql .= ($i > 0 ? ' OR ' : '') . 'weu.cal_login = ?';
        $query_params[] = $participants[$i];
    }
    // Make sure we don't get something past the end date of the event we're saving.
    $res = dbi_execute($sql . ' )', $query_params);
    if ($res) {
        $duration1 = sprintf("%d", $duration);
        $time1 = sprintf("%d%02d00", $hour, $minute);
        while ($row = dbi_fetch_row($res)) {
            // Add to an array to see if it has been found already for the next part.
            $found[$count++] = $row[4];
            // See if events overlaps one another.
            if ($row[4] != $id) {
                $cntkey = $row[0] . '-' . $row[7];
                $duration2 = $row[2];
                $time2 = sprintf("%06d", $row[1]);
                if (empty($evtcnt[$cntkey])) {
                    $evtcnt[$cntkey] = 0;
                } else {
                    $evtcnt[$cntkey]++;
                }
                $over_limit = $LIMIT_APPTS == 'Y' && $LIMIT_APPTS_NUMBER > 0 && $evtcnt[$cntkey] >= $LIMIT_APPTS_NUMBER ? 1 : 0;
                if ($over_limit || times_overlap($time1, $duration1, $time2, $duration2)) {
                    $conflicts .= '
            <li>';
                    if ($single_user != 'Y') {
                        user_load_variables($row[0], 'conflict_');
                        $conflicts .= $GLOBALS['conflict_fullname'] . ': ';
                    }
                    $conflicts .= ($row[5] == 'C' && $row[0] != $login && !$is_assistant && !$is_nonuser_admin ? '(' . $confidentialStr . ')' : ($row[5] == 'R' && $row[0] != $login ? '( ' . $privateStr . ')' : '<a href="view_entry.php?id=' . $row[4] . ($row[0] != $login ? '&amp;user='******'') . '">' . $row[3] . '</a>')) . ($duration2 == 1440 && $time2 == 0 ? ' (' . $allDayStr . ')' : ' (' . display_time($row[7] . $time2) . ($duration2 > 0 ? '-' . display_time($row[7] . add_duration($time2, $duration2)) : '') . ')') . ' ' . $onStr . ' ' . date_to_str(date('Ymd', date_to_epoch($row[7] . sprintf("%06d", $row[1])))) . ($over_limit ? ' (' . str_replace('XXX', $LIMIT_APPTS_NUMBER, $exceedsStr) . ')' : '') . '</li>';
                }
            }
        }
        dbi_free_result($res);
    } else {
        db_error(true);
    }
    for ($q = 0; $q < $partcnt; $q++) {
        // Read repeated events only once for a participant for performance reasons.
        $jumpdate = gmdate('Ymd', $dates[count($dates) - 1]);
        $repeated_events = query_events($participants[$q], true, 'AND ( we.cal_date <= ' . $jumpdate . ' AND ( wer.cal_end IS NULL OR wer.cal_end >= ' . gmdate('Ymd', $dates[0]) . ' ) )');
        for ($i = 0; $i < $datecnt; $i++) {
            $dateYmd = gmdate('Ymd', $dates[$i]);
            $list = get_repeating_entries($participants[$q], $dateYmd);
            for ($j = 0, $listcnt = count($list); $j < $listcnt; $j++) {
                // OK we've narrowed it down to a day, now I just gotta check the time...
                // I hope this is right...
                $row = $list[$j];
                if ($row->getID() != $id && !in_array($row->getID(), $found) && ($row->getExtForID() == '' || $row->getExtForID() != $id)) {
                    $time2 = sprintf("%06d", $row->getTime());
                    $duration2 = $row->getDuration();
                    if (times_overlap($time1, $duration1, $time2, $duration2)) {
                        $conflicts .= '
            <li>';
                        if ($single_user != 'Y') {
                            user_load_variables($row->getLogin(), 'conflict_');
                            $conflicts .= $GLOBALS['conflict_fullname'] . ': ';
                        }
                        $conflicts .= ($row->getAccess() == 'C' && $row->getLogin() != $login && !$is_assistant && !$is_nonuser_admin ? '(' . $confidentialStr . ')' : ($row->getAccess() == 'R' && $row->getLogin() != $login ? '(' . $privateStr . ')' : '<a href="view_entry.php?id=' . $row->getID() . (!empty($user) && $user != $login ? '&amp;user='******'') . '">' . $row->getName() . '</a>')) . ' (' . display_time($row->getDate() . $time2) . ($duration2 > 0 ? '-' . display_time($row->getDate() . add_duration($time2, $duration2)) : '') . ')' . ' ' . $onStr . ' ' . date_to_str($dateYmd) . '</li>';
                    }
                }
            }
        }
    }
    return $conflicts;
}
예제 #6
0
파일: view_entry.php 프로젝트: rhertzog/lcs
// Remove the '"' character since it causes some mailers to barf
$subject = str_replace(' "', '', $subject);
$subject = htmlspecialchars($subject);
$event_repeats = false;
// Build info string for repeating events and end date.
$res = dbi_execute('SELECT cal_type FROM webcal_entry_repeats
  WHERE cal_id = ?', array($id));
$rep_str = '';
if ($res) {
    if ($tmprow = dbi_fetch_row($res)) {
        $event_repeats = true;
    }
    dbi_free_result($res);
}
/* calculate end time */
$end_str = $event_time >= 0 && $duration > 0 ? '-' . display_time($display_date . add_duration($event_time, $duration % 1440), 2) : '';
// get the email adress of the creator of the entry
user_load_variables($create_by, 'createby_');
$email_addr = empty($createby_email) ? '' : $createby_email;
// If Private and not this user's event or
// Confidential and not user's and not assistant,
// then they cannot see name or description.
// if ( $row[8] == "R" && ! $is_my_event && ! $is_admin ) {
if ($cal_access == 'R' && !$is_my_event && !access_is_enabled()) {
    $is_private = true;
    $description = $name = '[' . translate('Private') . ']';
} else {
    if ($cal_access == 'C' && !$is_my_event && !$is_assistant && !access_is_enabled()) {
        $is_confidential = true;
        $description = $name = '[' . translate('Confidential') . ']';
    }
           <td colspan="2">
             <input type="text" name="duration_h" id="duration_h" size="2" ' . 'maxlength="2" value="';
         if ($allday != 'Y') {
             printf("%d", $dur_h);
         }
         echo '" />:
             <input type="text" name="duration_m" id="duration_m" size="2" ' . 'maxlength="2" value="';
         if ($allday != 'Y') {
             printf("%02d", $duration - $dur_h * 60);
         }
         echo '" />&nbsp;(<label for="duration_h">' . $hoursStr . '</label>: <label for="duration_m">' . $minutStr . '</label>)
           </td>
         </tr>';
     } else {
         echo '
         <span id="timeentryend" class="tooltip" title="' . tooltip('end-time-help') . '">&nbsp;-&nbsp;' . time_selection('end_', $id ? add_duration($cal_time, $duration) : $cal_time) . '</span>
       </td>
     </tr>';
     }
 } else {
     // eType == task
     echo ' class="tooltip" title="' . tooltip('time-help') . '">' . translate('Start Time') . ':</td>
       <td colspan="2">' . time_selection('entry_', $cal_time) . '</td>
     </tr>
     <tr>
       <td colspan="3">&nbsp;</td>
     </tr>
     <tr>
       <td class="tooltip" title="' . tooltip('date-help') . '">' . translate('Due Date') . ':</td>
       <td colspan="2">' . date_selection('due_', $due_date) . '</td>
     </tr>
예제 #8
0
            } else {
                // cek apakah child sendiri ?
                $query_exist = mysql_query("select count(table_id) as jumlah from table_mergers where table_parent_id = '" . $table_id . "' and table_id = '" . $row['table_id'] . "'");
                $row_exist = mysql_fetch_array($query_exist);
                // jika ya tampilkan
                if ($row_exist['jumlah'] > 0) {
                    update_merger_status($row['table_id'], 0);
                    delete_merger_table($table_id, $row['table_id']);
                    if ($_POST['i_table_id_' . $row['table_id']] == 1) {
                        $data = "'',\n\t\t\t\t\t\t\t'{$table_id}',\n\t\t\t\t\t\t\t'" . $row['table_id'] . "'\n\t\t\t\t\t\t\t";
                        save_merger_table($data);
                        update_merger_status($row['table_id'], 2);
                    }
                }
            }
        }
        header("location: order.php?building_id={$building_id}");
        break;
    case 'add_duration':
        $reserved_id = $_GET['reserved_id'];
        $i_duration = $_POST['i_duration'];
        $building_id = isset($_GET['building_id']) ? $_GET['building_id'] : 0;
        $get_reservation_time = get_reservation_time($reserved_id);
        //echo $get_reservation_time;
        $minute = $i_duration;
        $add = strtotime('+' . $minute . ' minutes', strtotime($get_reservation_time));
        $add = date("Y-m-d H:i:s", $add);
        add_duration($reserved_id, $add);
        header("location: order.php?building_id={$building_id}");
        break;
}