示例#1
0
function format_time($d, $t)
{
    global $time_names;
    if ($d === null || $t === null) {
        return "";
    } elseif (is_valid_day($d) && is_valid_time($t)) {
        return "{$d} at {$time_names[$t]}";
    } else {
        return '<invalid time>';
    }
}
/**
 * Save acf metadata when post is saved
 * @param type $post_id
 * @return type
 */
function my_acf_save_post($post_id)
{
    // bail early if no ACF data
    if (empty($_POST['fields']) || empty($_POST['fields']['field_546304dab92d4']) || empty($_POST['fields']['field_546304dab93c8']) || empty($_POST['fields']['field_546613dab92d4'])) {
        return;
    }
    // array of field values
    $fields = $_POST['fields'];
    if (!is_valid_time($fields['field_546304dab92d4']) || !is_valid_time($fields['field_546304dab93c8'])) {
        return;
    }
    // if you want to see what is happening, add debug => true to the factory call
    $toggl_client = TogglClient::factory(array('api_key' => $GLOBALS['Toggl_Helper']->toggl_api_key, 'debug' => false));
    $today = $_POST['fields']['field_546613dab92d4'];
    //calculate duration of the toggl time entries
    $time_entries = get_time_entries($toggl_client, $today);
    if (!empty($time_entries)) {
        $time_entries_duration = 0;
        foreach ($time_entries as $entry) {
            $time_entries_duration += $entry['duration'];
        }
    } else {
        $time_entries_duration = 0;
    }
    $break_time = (double) $_POST['fields']['field_654304dab93c8'];
    if (is_float($break_time)) {
        $workday_in_seconds = get_workday_in_seconds($today) - $break_time * 60 * 60;
        //Lets minus the breaks
    } else {
        $workday_in_seconds = get_workday_in_seconds($today);
    }
    $other_works = $workday_in_seconds - $time_entries_duration;
    $_POST['fields']['field_546304ceb92d3'] = gmdate("H:i:s", $workday_in_seconds);
    if ($GLOBALS['Toggl_Helper']->other_works_id > 0 && $other_works > 0 && is_numeric($other_works)) {
        $toggl_client->CreateTimeEntry(array('time_entry' => array('description' => $GLOBALS['Toggl_Helper']->description, 'pid' => $GLOBALS['Toggl_Helper']->other_works_id, 'created_with' => 'Wordpress-plugin', 'duration' => (int) $other_works, 'start' => $today . 'T17:00:00+00:00')));
    }
    $total = $GLOBALS['Toggl_Helper']->workhours * 60 * 60 - $workday_in_seconds;
    $pre = '-';
    if ($total < 0) {
        $total = -1 * $total;
        $pre = '+';
    }
    $_POST['fields']['field_546304dab94d3'] = $pre . gmdate("H:i:s", $total);
}
示例#3
0
// Defaults
$Day = "";
$STime = "";
$ETime = "";
$Members = array();
$event = array();
$event['Location'] = "";
$event['Summary'] = "Study Group Event";
$event['Description'] = "Meet to study for classes";
if (isset($_GET['group_id'])) {
    $group = get_group($db, $_GET['group_id']);
    $event['Summary'] = "Meeting for " . $group['name'];
    if (is_valid_day($group['day'])) {
        $Day = next_weekday($group['day'])->format("Y-m-d");
    }
    if (is_valid_time($group['time'])) {
        $STime = sprintf("%02d:00", $group['time']);
        $ETime = sprintf("%02d:00", ($group['time'] + 1) % 24);
    }
    $Members = get_group_members($db, $_GET['group_id']);
    $event['Location'] = $group['place'];
}
if (isset($_POST['Day'])) {
    $Day = $_POST['Day'];
}
if (isset($_POST['STime'])) {
    $STime = $_POST['STime'];
}
if (isset($_POST['ETime'])) {
    $ETime = $_POST['ETime'];
}
示例#4
0
         $errors['course'] = "choose a course you are registered for";
     }
 }
 // Fill in a useful default name
 if ($form['name'] === '' && !isset($errors['course'])) {
     $course = get_course($db, $form['course']);
     $form['name'] = "{$course['department']} {$course['number']} study group";
 }
 // Check that the day and time are valid
 if (isset($_POST['day']) && $_POST['day'] !== "" || isset($_POST['time']) && $_POST['time'] !== "") {
     if (empty($_POST['day']) || !is_valid_day($_POST['day'])) {
         $errors['day'] = "please choose a valid day";
     } else {
         $form['day'] = $_POST['day'];
     }
     if (!isset($_POST['time']) || $_POST['time'] === "" || !is_valid_time($_POST['time'])) {
         $errors['time'] = 'please choose a valid time';
     } else {
         $form['time'] = $_POST['time'];
     }
 }
 // Check if all the user ids are numeric
 if (isset($_POST['members']) && is_array($_POST['members'])) {
     foreach ($_POST['members'] as $member_id) {
         if (is_numeric($member_id)) {
             $form['members'][] = $member_id;
         } else {
             if (!$errors['members']) {
                 $errors['members'] = 'invalid user id';
             }
         }
示例#5
0
function valid_time($time)
{
    return is_valid_time($valid_time);
}
示例#6
0
     $q->execute();
     $campus = $q->fetch();
     $place = $campus['name'];
     $stmt = $db->prepare("UPDATE groups SET campus=:campus WHERE id=:group_id");
     $stmt->bindValue(":group_id", $group['id']);
     $stmt->bindValue(":campus", $place);
     $stmt->execute();
 }
 if (!empty($_POST['building'])) {
     $place = $_POST['building'];
     $stmt = $db->prepare("UPDATE groups SET place=:place WHERE id=:group_id");
     $stmt->bindValue(":group_id", $group['id']);
     $stmt->bindValue(":place", $place);
     $stmt->execute();
 }
 if (isset($_POST['day']) && isset($_POST['time']) && is_valid_day($_POST['day']) && is_valid_time($_POST['time'])) {
     $stmt = $db->prepare("UPDATE groups SET day=:day, time=:time WHERE id=:group_id");
     $stmt->bindValue(":group_id", $group['id']);
     $stmt->bindValue(":day", $_POST['day']);
     $stmt->bindValue(":time", $_POST['time']);
     $stmt->execute();
 }
 $private = !empty($_POST['private']);
 if ($group['is_private'] != $private) {
     $stmt = $db->prepare("UPDATE groups SET is_private=:private WHERE id=:group_id");
     $stmt->bindValue(":group_id", $group['id']);
     $stmt->bindValue(":private", $private);
     $stmt->execute();
 }
 header("Location: group.php?id=" . urlencode($group['id']));
 exit(0);