Example #1
0
function get_all($mysqli, $friend_ids)
{
    if (!isset($_SESSION)) {
        session_start();
    }
    if (!isset($_SESSION["id"]) || !valid_friends($friend_ids)) {
        die("[]");
    }
    $my_id = $_SESSION["id"];
    $friend_ids[] = $my_id;
    $ids = $friend_ids;
    sort($ids);
    $room_id = get_room_id($mysqli, $ids);
    return get_messages($mysqli, $room_id);
}
Example #2
0
function process_it() {
	$con = connect_db();
	$date = date('Y-m-d', strtotime(htmlspecialchars($_POST['date'])));
	unset($_POST['date']);  // remove the date from $_POST, leaving only room=>text pairs
	if (!($stmt = $con->prepare("INSERT INTO meetings
										 (subject,
										  start_datetime,
										  end_datetime,
										  F_Id)
							 	 VALUES  (?, ?, ?, ?)"))) {
		echo 'Prepare failed: ' . $con->errno . ' - ' . $con->error;
		exit;
	}
	if (!($stmt->bind_param('sssi', $subject, $start_datetime, $end_datetime, $room_id))) {
		echo 'BindParam failed: ' . $stmt->errno . ' - ' . $stmt->error;
		exit;
	}
	foreach ($_POST as $room => $text) {
		$room = htmlspecialchars($room);
		$text = htmlspecialchars($text);
		$room_id = get_room_id(str_replace('_', ' ', $room));

		$con->query("DELETE FROM meetings
				     WHERE F_Id='$room_id'
				     AND date(start_datetime)='$date'");
		$meetings = explode("\r\n", $text);
		if (strlen(preg_replace('/\s+/', '', $meetings[0])) > 1) {
			foreach ($meetings as $meet) {
				$meeting = create_meeting_object($meet);
				if ($meeting !== false) {
					$start_datetime = $date . ' ' . $meeting['start'];
					$end_datetime = $date . ' ' . $meeting['end'];
					$subject = $meeting['subject'];
					if (!($stmt->execute())) {
						echo 'Execute failed: ' . $stmt->errno . ' - ' . $stmt->error;
						exit;
					}
				}
				elseif (strlen($meet) > 1) {
					echo utf8_encode('Noe gikk galt under lagring av møtet: ') . $meet .
									 '<br>Gå tilbake for å rette opp';
					exit;
				}
			}
		}
	}
	return true;
}
Example #3
0
function commit_file_to_db($file, $room_name) {
	$f = fopen($file, 'r');
	$room_id = get_room_id($room_name);
	$header = fgets($f);

	$con = connect_db();
	$con->query("DELETE FROM meetings WHERE F_Id='$room_id'");

	if (!($stmt = $con->prepare("INSERT INTO meetings
											 (subject,
											  start_datetime,
											  end_datetime,
											  F_Id)
								 VALUES 	 (?, ?, ?, ?)"))) {
		echo 'Prepare failed: ' . $con->errno . ' - ' . $con->error;
		exit;
	}

	if (!($stmt->bind_param('sssi', $subject, $start_datetime, $end_datetime, $room_id))) {
		echo 'BindParam failed: ' . $stmt->errno . ' - ' . $stmt->error;
		exit;
	}
	while ($line = fgets($f)) {
		$data = parse_line($line);
		if ($data) {
			extract($data); // See parse_line() for extracted values
			if (strlen($subject) > 1) {
				if (strpos($subject, 'Copy: ') === 0 || strpos($subject, 'Kopi: ') === 0)
					$subject = substr($subject, 6);
				$subject = utf8_encode($subject);
				if (!($stmt->execute())) {
					echo 'Execute() failed: ' . $stmt->errno . ' - ' . $stmt->error . '<br>';
					exit;
				}
			}
		}
	}
	return true;
}
Example #4
0
function process_event($vevent)
{
    global $import_default_type, $skip;
    global $morningstarts, $morningstarts_minutes, $resolution;
    // We are going to cache the settings ($resolution etc.) for the rooms
    // in order to avoid lots of database lookups
    static $room_settings = array();
    // Set up the booking with some defaults
    $booking = array();
    $booking['status'] = 0;
    $booking['rep_type'] = REP_NONE;
    $booking['type'] = $import_default_type;
    // Parse all the lines first because we'll need to get the start date
    // for calculating some of the other settings
    $properties = array();
    $problems = array();
    $line = current($vevent);
    while ($line !== FALSE) {
        $property = parse_ical_property($line);
        // Ignore any sub-components (eg a VALARM inside a VEVENT) as MRBS does not
        // yet handle things like reminders.  Skip through to the end of the sub-
        // component.   Just in case you can have sub-components at a greater depth
        // than 1 (not sure if you can), make sure we've got to the matching END.
        if ($property['name'] != 'BEGIN') {
            $properties[$property['name']] = array('params' => $property['params'], 'value' => $property['value']);
        } else {
            $component = $property['value'];
            while (!($property['name'] == 'END' && $property['value'] == $component) && ($line = next($vevent))) {
                $property = parse_ical_property($line);
            }
        }
        $line = next($vevent);
    }
    // Get the start time because we'll need it later
    if (!isset($properties['DTSTART'])) {
        trigger_error("No DTSTART", E_USER_WARNING);
    } else {
        $booking['start_time'] = get_time($properties['DTSTART']['value'], $properties['DTSTART']['params']);
    }
    // Now go through the rest of the properties
    foreach ($properties as $name => $details) {
        switch ($name) {
            case 'ORGANIZER':
                $booking['create_by'] = get_create_by($details['value']);
                break;
            case 'SUMMARY':
                $booking['name'] = $details['value'];
                break;
            case 'DESCRIPTION':
                $booking['description'] = $details['value'];
                break;
            case 'LOCATION':
                $error = '';
                $booking['room_id'] = get_room_id($details['value'], $error);
                if ($booking['room_id'] === FALSE) {
                    $problems[] = $error;
                }
                break;
            case 'DTEND':
                $booking['end_time'] = get_time($details['value'], $details['params']);
                break;
            case 'DURATION':
                trigger_error("DURATION not yet supported by MRBS", E_USER_WARNING);
                break;
            case 'RRULE':
                $rrule_errors = array();
                $repeat_details = get_repeat_details($details['value'], $booking['start_time'], $rrule_errors);
                if ($repeat_details === FALSE) {
                    $problems = array_merge($problems, $rrule_errors);
                } else {
                    foreach ($repeat_details as $key => $value) {
                        $booking[$key] = $value;
                    }
                }
                break;
            case 'CLASS':
                if (in_array($details['value'], array('PRIVATE', 'CONFIDENTIAL'))) {
                    $booking['status'] |= STATUS_PRIVATE;
                }
                break;
            case 'STATUS':
                if ($details['value'] == 'TENTATIVE') {
                    $booking['status'] |= STATUS_TENTATIVE;
                }
                break;
            case 'UID':
                $booking['ical_uid'] = $details['value'];
                break;
            case 'SEQUENCE':
                $booking['ical_sequence'] = $details['value'];
                break;
            case 'LAST-MODIFIED':
                // We probably ought to do something with LAST-MODIFIED and use it
                // for the timestamp field
                break;
            default:
                break;
        }
    }
    // If we didn't manage to work out a username then just put the booking
    // under the name of the current user
    if (!isset($booking['create_by'])) {
        $booking['create_by'] = getUserName();
    }
    // A SUMMARY is optional in RFC 5545, however a brief description is mandatory
    // in MRBS.   So if the VEVENT didn't include a name, we'll give it one
    if (!isset($booking['name'])) {
        $booking['name'] = "Imported event - no SUMMARY name";
    }
    // On the other hand a UID is mandatory in RFC 5545.   We'll be lenient and
    // provide one if it is missing
    if (!isset($booking['ical_uid'])) {
        $booking['ical_uid'] = generate_global_uid($booking['name']);
        $booking['sequence'] = 0;
        // and we'll start the sequence from 0
    }
    // LOCATION is optional in RFC 5545 but is obviously mandatory in MRBS.
    // We could maybe have a default room on the form and use that
    if (!isset($booking['room_id'])) {
        $problems[] = get_vocab("no_LOCATION");
    }
    if (empty($problems)) {
        // Get the area settings for this room, if we haven't got them already
        if (!isset($room_settings[$booking['room_id']])) {
            get_area_settings(get_area($booking['room_id']));
            $room_settings[$booking['room_id']]['morningstarts'] = $morningstarts;
            $room_settings[$booking['room_id']]['morningstarts_minutes'] = $morningstarts_minutes;
            $room_settings[$booking['room_id']]['resolution'] = $resolution;
        }
        // Round the start and end times to slot boundaries
        $date = getdate($booking['start_time']);
        $m = $date['mon'];
        $d = $date['mday'];
        $y = $date['year'];
        $am7 = mktime($room_settings[$booking['room_id']]['morningstarts'], $room_settings[$booking['room_id']]['morningstarts_minutes'], 0, $m, $d, $y);
        $booking['start_time'] = round_t_down($booking['start_time'], $room_settings[$booking['room_id']]['resolution'], $am7);
        $booking['end_time'] = round_t_up($booking['end_time'], $room_settings[$booking['room_id']]['resolution'], $am7);
        // Make the bookings
        $bookings = array($booking);
        $result = mrbsMakeBookings($bookings, NULL, FALSE, $skip);
        if ($result['valid_booking']) {
            return TRUE;
        }
    }
    // There were problems - list them
    echo "<div class=\"problem_report\">\n";
    echo get_vocab("could_not_import") . " UID:" . htmlspecialchars($booking['ical_uid']);
    echo "<ul>\n";
    foreach ($problems as $problem) {
        echo "<li>" . htmlspecialchars($problem) . "</li>\n";
    }
    if (!empty($result['rules_broken'])) {
        echo "<li>" . get_vocab("rules_broken") . "\n";
        echo "<ul>\n";
        foreach ($result['rules_broken'] as $rule) {
            echo "<li>{$rule}</li>\n";
        }
        echo "</ul></li>\n";
    }
    if (!empty($result['conflicts'])) {
        echo "<li>" . get_vocab("conflict") . "\n";
        echo "<ul>\n";
        foreach ($result['conflicts'] as $conflict) {
            echo "<li>{$conflict}</li>\n";
        }
        echo "</ul></li>\n";
    }
    echo "</ul>\n";
    echo "</div>\n";
    return FALSE;
}
{
    $mysqli->query("DELETE FROM `chat` WHERE roomid={$room_id}");
}
$json = json_decode(file_get_contents('php://input'));
//get data from json headers
if (!isset($json) || !isset($json->users)) {
    die;
}
if (!isset($_SESSION)) {
    session_start();
}
if (!isset($_SESSION['name'])) {
    die;
}
$user = $_SESSION['name'];
$users = $json->users;
$friend_ids = get_users_ids($mysqli, $users);
$ids = array_merge($friend_ids, (array) $_SESSION["id"]);
sort($ids);
if (valid_friends($users)) {
    $room_id = get_room_id($mysqli, $ids);
    if ($room_id == -1) {
        die;
    }
    delete_all_messages($mysqli, $room_id);
    die("1");
}
die;
?>