Esempio n. 1
0
function translate()
{
    global $phpc_locale_path;
    if (!is_admin()) {
        permission_error(__('Need to be admin'));
        exit;
    }
    $handle = opendir($phpc_locale_path);
    if (!$handle) {
        return soft_error("Error reading locale directory.");
    }
    $output_tag = tag('div', tag('h2', __('Translate')));
    while (($filename = readdir($handle)) !== false) {
        $pathname = "{$phpc_locale_path}/{$filename}";
        if (strncmp($filename, ".", 1) == 0 || !is_dir($pathname)) {
            continue;
        }
        $msgs_path = "{$pathname}/LC_MESSAGES";
        $hash = parse_po_file("{$msgs_path}/messages.po");
        if ($hash === FALSE) {
            print nl2br("Error reading '{$msgs_path}/messages.po', aborted.\n");
        } else {
            $out = "{$msgs_path}/messages.mo";
            write_mo_file($hash, $out);
        }
        $output_tag->add(tag('div', sprintf(__('Translated "%s"'), $filename)));
    }
    closedir($handle);
    return $output_tag;
}
function category_submit()
{
    global $vars, $phpcdb, $phpc_script, $phpc_cal;
    if (empty($vars["text-color"]) || empty($vars["bg-color"])) {
        $page = "{$phpc_script}?action=category_form";
        if (!empty($vars["cid"])) {
            $page .= "&cid={$vars["cid"]}";
        }
        if (!empty($vars["catid"])) {
            $page .= "&catid={$vars["catid"]}";
        }
        return message_redirect(__("Color not specified."), $page);
    }
    // The current widget produces hex values without the "#".
    //   We may in the future want to allow different input, so store the
    //   values with the "#"
    $text_color = '#' . $vars["text-color"];
    $bg_color = '#' . $vars["bg-color"];
    if (empty($vars['gid']) || strlen($vars['gid']) == 0) {
        $gid = 0;
    } else {
        $gid = $vars['gid'];
    }
    if (!check_color($text_color) || !check_color($bg_color)) {
        soft_error(__("Invalid color."));
    }
    if (!isset($vars['catid'])) {
        $modify = false;
        if (!isset($vars['cid'])) {
            $cid = null;
            if (!is_admin()) {
                permission_error(__('You do not have permission to add categories to all calendars.'));
            }
        } else {
            $cid = $vars['cid'];
            $calendar = $phpcdb->get_calendar($cid);
            if (!$calendar->can_admin()) {
                permission_error(__('You do not have permission to add categories to this calendar.'));
            }
        }
        $catid = $phpcdb->create_category($cid, $vars["name"], $text_color, $bg_color, $gid);
    } else {
        $modify = true;
        $catid = $vars['catid'];
        $category = $phpcdb->get_category($catid);
        if (!(empty($category['cid']) && is_admin() || $phpcdb->get_calendar($category["cid"])->can_admin())) {
            soft_error(__("You do not have permission to modify this category."));
        }
        $phpcdb->modify_category($catid, $vars['name'], $text_color, $bg_color, $gid);
    }
    $page = "{$phpc_script}?action=cadmin&phpcid=" . $vars['phpcid'];
    if ($modify) {
        return message_redirect(__("Modified category: ") . $catid, $page);
    }
    if ($catid > 0) {
        return message_redirect(__("Created category: ") . $catid, $page);
    }
    return tag('div', attributes('class="phpc-error"'), __('Error submitting category.'));
}
Esempio n. 3
0
function cadmin()
{
    global $phpc_cal;
    if (!$phpc_cal->can_admin()) {
        permission_error(__('You must be logged in as an admin.'));
    }
    $index = tag('ul', tag('li', tag('a', attrs('href="#phpc-config"'), __('Calendar Configuration'))), tag('li', tag('a', attrs('href="#phpc-users"'), __('Users'))), tag('li', tag('a', attrs('href="#phpc-categories"'), __('Categories'))), tag('li', tag('a', attrs('href="#phpc-groups"'), __('Groups'))));
    return tag('div', attrs("class=\"phpc-tabs\""), $index, config_form(), user_list(), category_list(), group_list());
}
Esempio n. 4
0
function admin()
{
    global $phpc_version;
    if (!is_admin()) {
        permission_error(__('You must be logged in as an admin.'));
    }
    $menu = tag('ul', tag('li', tag('a', attrs('href="#phpc-admin-calendars"'), __('Calendars'))), tag('li', tag('a', attrs('href="#phpc-admin-users"'), __('Users'))), tag('li', tag('a', attrs('href="#phpc-admin-import"'), __('Import'))), tag('li', tag('a', attrs('href="#phpc-admin-translate"'), __('Translate'))));
    $version = tag('div', attrs('class="phpc-bar ui-widget-content"'), __('Version') . ": {$phpc_version}");
    return tag('', tag('div', attrs('class="phpc-tabs"'), $menu, calendar_list(), user_list(), import(), translation_link()), $version);
}
Esempio n. 5
0
function field_submit()
{
    global $vars, $phpcdb, $phpc_script, $phpc_cal;
    $form_page = "{$phpc_script}?action=field_form";
    if (!empty($vars["cid"])) {
        $form_page .= "&cid={$vars["cid"]}";
    }
    if (!empty($vars["fid"])) {
        $form_page .= "&fid={$vars["fid"]}";
    }
    if (empty($vars["name"])) {
        return input_error(__("Name not specified."), $form_page);
    }
    $required = !empty($vars['name']) && $vars['required'] == '1';
    if (empty($vars['format'])) {
        $format = false;
    } else {
        $format = $vars['format'];
    }
    if (!isset($vars['fid'])) {
        $modify = false;
        if (!isset($vars['cid'])) {
            $cid = null;
            if (!is_admin()) {
                permission_error(__('You do not have permission to add fields to all calendars.'));
            }
        } else {
            $cid = $vars['cid'];
            $calendar = $phpcdb->get_calendar($cid);
            if (!$calendar->can_admin()) {
                permission_error(__('You do not have permission to add fields to this calendar.'));
            }
        }
        $fid = $phpcdb->create_field($cid, $vars["name"], $required, $format);
    } else {
        $modify = true;
        $fid = $vars['fid'];
        $field = $phpcdb->get_field($fid);
        if (!(empty($field['cid']) && is_admin() || $phpcdb->get_calendar($field["cid"])->can_admin())) {
            permission_error(__("You do not have permission to modify this field."));
        }
        $phpcdb->modify_field($fid, $vars['name'], $required, $format);
    }
    $page = "{$phpc_script}?action=cadmin&phpcid={$vars['phpcid']}#phpc-fields";
    if ($modify) {
        return message_redirect(__("Modified field: ") . $fid, $page);
    }
    if ($fid > 0) {
        return message_redirect(__("Created field: ") . $fid, $page);
    }
    return tag('div', attributes('class="phpc-error"'), __('Error submitting field.'));
}
Esempio n. 6
0
function group_submit()
{
    global $vars, $phpcdb, $phpc_script, $phpc_cal;
    if (!isset($vars['gid'])) {
        $modify = false;
        if (!isset($vars['cid'])) {
            $cid = null;
            if (!is_admin()) {
                permission_error(__('You do not have permission to add a global group.'));
            }
        } else {
            $cid = $vars['cid'];
            $calendar = $phpcdb->get_calendar($cid);
            if (!$calendar->can_admin()) {
                permission_error(__('You do not have permission to add a group to this calendar.'));
            }
        }
        $gid = $phpcdb->create_group($cid, $vars["name"]);
    } else {
        $modify = true;
        $gid = $vars['gid'];
        $group = $phpcdb->get_group($gid);
        if (!(empty($group['cid']) && is_admin() || $phpcdb->get_calendar($group["cid"])->can_admin())) {
            soft_error(__("You do not have permission to modify this group."));
        }
        $phpcdb->modify_group($gid, $vars['name']);
    }
    $page = "{$phpc_script}?action=cadmin&phpcid=" . $vars['cid'];
    if ($modify) {
        return message_redirect(__("Modified group: ") . $gid, $page);
    }
    if ($gid > 0) {
        return message_redirect(__("Created group: ") . $gid, $page);
    }
    return tag('div', attributes('class="phpc-error"'), __('Error submitting group.'));
}
Esempio n. 7
0
function process_form()
{
    global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script;
    if (!isset($vars['eid']) && !isset($vars['oid'])) {
        soft_error(__("Cannot create occurrence."));
    }
    $start_ts = get_timestamp("start");
    $end_ts = get_timestamp("end");
    switch ($vars["time-type"]) {
        case 'normal':
            $time_type = 0;
            break;
        case 'full':
            $time_type = 1;
            break;
        case 'tba':
            $time_type = 2;
            break;
        default:
            soft_error(__("Unrecognized Time Type."));
    }
    $duration = $end_ts - $start_ts;
    if ($duration < 0) {
        soft_error(__("An event cannot have an end earlier than its start."));
    }
    verify_token();
    if (!$phpc_cal->can_write()) {
        permission_error(__('You do not have permission to write to this calendar.'));
    }
    if (!isset($vars['oid'])) {
        $modify = false;
        if (!isset($vars["eid"])) {
            soft_error(__("EID not set."));
        }
        $oid = $phpcdb->create_occurrence($vars["eid"], $time_type, $start_ts, $end_ts);
    } else {
        $modify = true;
        $oid = $vars["oid"];
        $phpcdb->modify_occurrence($oid, $time_type, $start_ts, $end_ts);
    }
    if ($oid != 0) {
        if ($modify) {
            $message = __("Modified occurence: ");
        } else {
            $message = __("Created occurence: ");
        }
        return message_redirect(tag('', $message, create_event_link($oid, 'display_event', $oid)), "{$phpc_script}?action=display_event&phpcid={$phpcid}&oid={$oid}");
    } else {
        return message_redirect(__('Error submitting occurrence.'), "{$phpc_script}?action=display_month&phpcid={$phpcid}");
    }
}
Esempio n. 8
0
function process_form()
{
    global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script, $phpc_user;
    // When modifying events, this is the value of the checkbox that
    //   determines if the date should change
    $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']);
    if ($modify_occur) {
        $start_ts = get_timestamp("start");
        $end_ts = get_timestamp("end");
        switch ($vars["time-type"]) {
            case 'normal':
                $time_type = 0;
                break;
            case 'full':
                $time_type = 1;
                break;
            case 'tba':
                $time_type = 2;
                break;
            default:
                soft_error(__("Unrecognized Time Type."));
        }
        $duration = $end_ts - $start_ts;
        if ($duration < 0) {
            message(__("An event cannot have an end earlier than its start."));
            return display_form();
        }
    }
    verify_token();
    if (0) {
        permission_error(__('You do not have permission to write to this calendar.'));
    }
    if ($phpc_cal->can_create_readonly() && !empty($vars['readonly'])) {
        $readonly = true;
    } else {
        $readonly = false;
    }
    $catid = empty($vars['catid']) ? false : $vars['catid'];
    if (!isset($vars['eid'])) {
        $modify = false;
        $eid = $phpcdb->create_event($phpcid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid);
    } else {
        $modify = true;
        $eid = $vars['eid'];
        $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid);
        if ($modify_occur) {
            $phpcdb->delete_occurrences($eid);
        }
    }
    if ($modify_occur) {
        $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
        $occurrences = 1;
        switch ($vars["repeats"]) {
            case "never":
                break;
            case 'daily':
                if (!isset($vars["every-day"])) {
                    soft_error(__("Required field \"every-day\" is not set."));
                }
                $ndays = $vars["every-day"];
                if ($ndays < 1) {
                    soft_error(__("every-day must be greater than 1"));
                }
                $daily_until = get_timestamp("daily-until");
                while ($occurrences <= 730) {
                    $start_ts = add_days($start_ts, $ndays);
                    $end_ts = add_days($end_ts, $ndays);
                    if (days_between($start_ts, $daily_until) < 0) {
                        break;
                    }
                    $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
                    $occurrences++;
                }
                break;
            case 'weekly':
                if (!isset($vars["every-week"])) {
                    soft_error(__("Required field \"every-week\" is not set."));
                }
                if ($vars["every-week"] < 1) {
                    soft_error(__("every-week must be greater than 1"));
                }
                $ndays = $vars["every-week"] * 7;
                $weekly_until = get_timestamp("weekly-until");
                while ($occurrences <= 730) {
                    $start_ts = add_days($start_ts, $ndays);
                    $end_ts = add_days($end_ts, $ndays);
                    if (days_between($start_ts, $weekly_until) < 0) {
                        break;
                    }
                    $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
                    $occurrences++;
                }
                break;
            case 'monthly':
                if (!isset($vars["every-month"])) {
                    soft_error(__("Required field \"every-month\" is not set."));
                }
                if ($vars["every-month"] < 1) {
                    soft_error(__("every-month must be greater than 1"));
                }
                $nmonths = $vars["every-month"];
                $monthly_until = get_timestamp("monthly-until");
                while ($occurrences <= 730) {
                    $start_ts = add_months($start_ts, $nmonths);
                    $end_ts = add_months($end_ts, $nmonths);
                    if (days_between($start_ts, $monthly_until) < 0) {
                        break;
                    }
                    $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
                    $occurrences++;
                }
                break;
            case 'yearly':
                if (!isset($vars["every-year"])) {
                    soft_error(__("Required field \"every-year\" is not set."));
                }
                if ($vars["every-year"] < 1) {
                    soft_error(__("every-month must be greater than 1"));
                }
                $nyears = $vars["every-year"];
                $yearly_until = get_timestamp("yearly-until");
                while ($occurrences <= 730) {
                    $start_ts = add_years($start_ts, $nyears);
                    $end_ts = add_years($end_ts, $nyears);
                    if (days_between($start_ts, $yearly_until) < 0) {
                        break;
                    }
                    $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
                    $occurrences++;
                }
                break;
            default:
                soft_error(__("Invalid event type."));
        }
    }
    if ($eid != 0) {
        if ($modify) {
            $message = __("Modified event: ");
        } else {
            $message = __("Created event: ");
        }
        /* before
        return message_redirect(tag($eid, $message,
        					create_event_link('', 'display_event',
        						$eid)), */
        return message_redirect(tag('', $message, create_event_link('', 'display_event', '')), "{$phpc_script}?action=display_event&phpcid={$phpcid}&oid={$oid}");
        /* <-- before last paremeter was &eid=$eid instead of &oid=$oid */
    } else {
        return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$phpcid}");
    }
}
Esempio n. 9
0
function process_form()
{
    global $vars, $phpcdb, $phpc_script, $phpc_user, $phpc_cal;
    // When modifying events, this is the value of the checkbox that
    //   determines if the date should change
    $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']);
    if ($modify_occur) {
        $start_ts = get_timestamp("start");
        $end_ts = get_timestamp("end");
        switch ($vars["time-type"]) {
            case 'normal':
                $time_type = 0;
                break;
            case 'full':
                $time_type = 1;
                break;
            case 'tba':
                $time_type = 2;
                break;
            default:
                soft_error(__("Unrecognized Time Type."));
        }
        $duration = $end_ts - $start_ts;
        if ($duration < 0) {
            throw new Exception(__("An event cannot have an end earlier than its start."));
        }
    }
    verify_token();
    if (!isset($vars['cid'])) {
        throw new Exception(__("Calendar ID is not set."));
    }
    $cid = $vars['cid'];
    $calendar = $phpcdb->get_calendar($cid);
    if (!$calendar->can_write()) {
        permission_error(__('You do not have permission to write to this calendar.'));
    }
    if ($calendar->can_create_readonly() && !empty($vars['readonly'])) {
        $readonly = true;
    } else {
        $readonly = false;
    }
    $catid = empty($vars['catid']) ? false : $vars['catid'];
    if (!isset($vars['eid'])) {
        $modify = false;
        $eid = $phpcdb->create_event($cid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid);
    } else {
        $modify = true;
        $eid = $vars['eid'];
        $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid);
        if ($modify_occur) {
            $phpcdb->delete_occurrences($eid);
        }
    }
    foreach ($phpc_cal->get_fields() as $field) {
        $fid = $field['fid'];
        if (empty($vars["phpc-field-{$fid}"])) {
            if ($field['required']) {
                throw new Exception(sprintf(__('Field "%s" is required but was not set.'), $field['name']));
            }
            continue;
        }
        $phpcdb->add_event_field($eid, $fid, $vars["phpc-field-{$fid}"]);
    }
    if ($modify_occur) {
        $occurrences = 0;
        $n = 1;
        $until = $start_ts;
        switch ($vars['repeats']) {
            case 'daily':
                check_input("every-day");
                $n = $vars["every-day"];
                $until = get_timestamp("daily-until");
                break;
            case 'weekly':
                check_input("every-week");
                $n = $vars["every-week"] * 7;
                $until = get_timestamp("weekly-until");
                break;
            case 'monthly':
                check_input("every-month");
                $n = $vars["every-month"];
                $until = get_timestamp("monthly-until");
                break;
            case 'yearly':
                check_input("every-year");
                $n = $vars["every-year"];
                $until = get_timestamp("yearly-until");
                break;
        }
        if ($n < 1) {
            soft_error(__('Increment must be 1 or greater.'));
        }
        while ($occurrences <= 730 && days_between($start_ts, $until) >= 0) {
            $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
            $occurrences++;
            switch ($vars["repeats"]) {
                case 'daily':
                case 'weekly':
                    $start_ts = add_days($start_ts, $n);
                    $end_ts = add_days($end_ts, $n);
                    break;
                case 'monthly':
                    $start_ts = add_months($start_ts, $n);
                    $end_ts = add_months($end_ts, $n);
                    break;
                case 'yearly':
                    $start_ts = add_years($start_ts, $n);
                    $end_ts = add_years($end_ts, $n);
                    break;
                default:
                    break 2;
            }
        }
    }
    if ($eid != 0) {
        if ($modify) {
            $message = __("Modified event: ");
        } else {
            $message = __("Created event: ");
        }
        return message_redirect(tag('', $message, create_event_link($eid, 'display_event', $eid)), "{$phpc_script}?action=display_event&eid={$eid}");
    } else {
        return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$cid}");
    }
}
Esempio n. 10
0
function import()
{
    global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script;
    if (!is_admin()) {
        permission_error(__('Need to be admin'));
        exit;
    }
    $form_page = "{$phpc_script}?action=admin#phpc-import";
    if (!empty($vars['port']) && strlen($vars['port']) > 0) {
        $port = $vars['port'];
    } else {
        $port = ini_get("mysqli.default_port");
    }
    $old_dbh = @new mysqli($vars['host'], $vars['username'], $vars['passwd'], $vars['dbname'], $port);
    if (!$old_dbh || mysqli_connect_errno()) {
        return message_redirect("Database connect failed (" . mysqli_connect_errno() . "): " . mysqli_connect_error(), $form_page);
    }
    $events_table = $vars['prefix'] . 'events';
    $users_table = $vars['prefix'] . 'users';
    // Create user lookup table
    $users = array('anonymous' => '0');
    foreach ($phpcdb->get_users() as $user) {
        $users[$user->get_username()] = $user->get_uid();
    }
    // Lookup old events
    $query = "SELECT YEAR(`startdate`) as `year`, " . "MONTH(`startdate`) as `month`, " . "DAY(`startdate`) as `day`, YEAR(`enddate`) as `endyear`," . "MONTH(`enddate`) as `endmonth`, DAY(`enddate`) as `endday`," . "HOUR(`starttime`) as `hour`, MINUTE(`starttime`) as `minute`," . "`duration`, `eventtype`, `subject`, `description`," . "`username`, `password`\n" . "FROM `{$events_table}`\n" . "LEFT JOIN `{$users_table}` USING (`uid`)\n";
    $sth = $old_dbh->query($query) or $phpcdb->db_error(__('Error selecting events in import'), $query);
    $events = 0;
    $occurrences = 0;
    while ($result = $sth->fetch_assoc()) {
        $username = $result['username'];
        if (empty($username) || strlen($username) == 0) {
            $uid = 0;
        } else {
            if (!isset($users[$username])) {
                $users[$username] = $phpcdb->create_user($username, $result['password'], false);
            }
            $uid = $users[$username];
        }
        $eid = $phpcdb->create_event($phpcid, $uid, $phpcdb->dbh->escape_string($result["subject"]), $phpcdb->dbh->escape_string($result["description"]), false, false);
        $events++;
        $eventtype = $result['eventtype'];
        // Full Day or None
        if ($eventtype == 2 || $eventtype == 4) {
            $time_type = 1;
        } elseif ($eventtype == 3) {
            $time_type = 2;
        } else {
            $time_type = 0;
        }
        $year = $result['year'];
        $month = $result['month'];
        $day = $result['day'];
        $hour = $result['hour'];
        $minute = $result['minute'];
        $duration = $result['duration'];
        $final_ts = mktime($hour, $minute, 0, $result['endmonth'], $result['endday'], $result['endyear']);
        while (true) {
            $start_ts = mktime($hour, $minute, 0, $month, $day, $year);
            if ($start_ts > $final_ts) {
                break;
            }
            $endminute = $minute + $duration % 60;
            $endhour = ($hour + floor($duration / 60)) % 24;
            $endday = $day + floor($endhour / 24);
            $end_ts = mktime($endhour, $endminute, 0, $month, $endday, $year);
            $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts);
            $occurrences++;
            // Increment start time
            switch ($eventtype) {
                case 1:
                    // Normal
                // Normal
                case 2:
                    // Full Day
                // Full Day
                case 3:
                    // TBA
                // TBA
                case 4:
                    // None
                    $day++;
                    break;
                case 5:
                    // Weekly
                    $day += 7;
                    break;
                case 6:
                    // Monthly
                    $month++;
                    break;
                case 7:
                    // Yearly
                    $year++;
                    break;
                default:
                    echo "bad event!!";
                    exit;
            }
        }
    }
    return message_redirect(sprintf(__("Created %s events with %s occurences"), $events, $occurrences), $form_page);
}