Beispiel #1
0
 function get()
 {
     if (observer_prohibited()) {
         return;
     }
     $channel = null;
     if (argc() > 1) {
         $channel = channelx_by_nick(argv(1));
     }
     if (!$channel) {
         notice(t('Channel not found.') . EOL);
         return;
     }
     // since we don't currently have an event permission - use the stream permission
     if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) {
         notice(t('Permissions denied.') . EOL);
         return;
     }
     $sql_extra = permissions_sql($channel['channel_id'], get_observer_hash(), 'event');
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $tabs = profile_tabs($a, True, $channel['channel_address']);
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 3 && intval(argv(2)) && intval(argv(3))) {
         $mode = 'view';
         $y = intval(argv(2));
         $m = intval(argv(3));
     }
     if (argc() <= 3) {
         $mode = 'view';
         $event_id = argv(2);
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval($channel['channel_id']));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled($channel['channel_id'], 'categories');
         $show_bd = perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_contacts');
         if (!$show_bd) {
             $sql_extra .= " and event.etype != 'birthday' ";
         }
         $category = '';
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(2) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d {$sql_extra} limit 1", intval($channel['channel_id']), intval($_GET['id']));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) {$sql_extra} ", intval($channel['channel_id']), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = false;
                 $drop = false;
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if (argv(2) === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event_cal.tpl");
         } else {
             $tpl = get_markup_template("events_cal-js.tpl");
         }
         $nick = $channel['channel_address'];
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/cal', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/cal/{$nick}/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/cal/{$nick}/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/cal/{$nick}/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$upload' => t('Import'), '$submit' => t('Submit'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false, '$tabs' => $tabs));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
 }
Beispiel #2
0
            }
            echo "are allowed to view this album.</p><div id='logindivcontent'>";
            require "login.php";
            echo "</div></div>";
            die;
        }
    }
    $dir = scandir(urldecode($album));
    for ($i = 0; $i < sizeof($dir); $i++) {
        $images[] = $album . $dir[$i];
    }
    if ($sort_all_by_age) {
        array_multisort(array_map('filemtime', $images), SORT_DESC, $images);
    }
} elseif ($action == "age") {
    $images = sort_by_date($groups, $album);
} elseif ($action == "random") {
    $images = sort_by_random($groups, $album);
} elseif ($action == "virtual") {
    $images = array();
    $lines = file(stripslashes(urldecode($album)));
    foreach ($lines as $line_num => $line) {
        $images[] = $line;
    }
} elseif ($action == "go_on") {
    // Do nothing
} else {
    die("Error");
}
$size_dir = sizeof($images);
$_SESSION['images'] = $images;
Beispiel #3
0
        $folders_sorted = array_reverse($folders_sorted, TRUE);
    }
} else {
    $folders_sorted = array();
}
//if there are no folders in the current directory
if (!empty($files['name'])) {
    if ($sort_by == 0) {
        natcasesort($files['name']);
        //natcasesort preserves the array keys
        $files_sorted = $files['name'];
    } elseif ($sort_by == 1) {
        asort($files['size'], SORT_NUMERIC);
        $files_sorted = $files['size'];
    } else {
        $files_sorted = sort_by_date($files['date'], $sort_order);
    }
    if ($sort_order == 1) {
        $files_sorted = array_reverse($files_sorted, TRUE);
    }
} else {
    $files_sorted = array();
}
//if there are no files in the current directory
//Sort the folders and files array -done
//Icons
if ($view_mode == 0) {
    $files_icons_array = icons($files['name'], $view_mode);
    $folder_icon = $view_mode == 0 ? '<img border="0" src="dirLIST_files/icons_large/folder.png">' : '<img src="dirLIST_files/icons/folder.gif"> ';
} elseif ($view_mode == 1 && $file_icons) {
    $files_icons_array = icons($files['name'], $view_mode);
Beispiel #4
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o = "";
    // tabs
    $o .= profile_tabs($a, True);
    $o .= '<h2>' . t('Events') . '</h2>';
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\tWHERE `event`.`uid` = %d\n\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
        $o .= '<div id="event-calendar-wrapper">';
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
        $o .= cal($y, $m, $links, ' eventcal');
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
        $o .= '</div>';
        $o .= '<div class="event-calendar-end"></div>';
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                if ($d !== $last_date) {
                    $o .= '<hr /><a name="link-' . $j . '" ><div class="event-list-date">' . $d . '</div></a>';
                }
                $last_date = $d;
                if ($rr['author-name']) {
                    $o .= '<a href="' . $rr['author-link'] . '" ><img src="' . $rr['author-avatar'] . '" height="32" width="32" />' . $rr['author-name'] . '</a>';
                }
                $o .= format_event_html($rr);
                $o .= !$rr['cid'] ? '<a href="' . $a->get_baseurl() . '/events/event/' . $rr['id'] . '" title="' . t('Edit event') . '" class="edit-event-link icon pencil"></a>' : '';
                if ($rr['plink']) {
                    $o .= '<a href="' . $rr['plink'] . '" title="' . t('link to source') . '" target="external-link" class="plink-event-link icon remote-link"></a></div>';
                }
                $o .= '<div class="clear"></div>';
            }
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $htpl = get_markup_template('event_head.tpl');
        $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = x($orig_event) && $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$e_text' => t('Event details'), '$e_desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #5
0
function events_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('all_events');
    if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : 'textareas'));
    $o = "";
    // tabs
    $channel = $a->get_channel();
    $tabs = profile_tabs($a, True, $channel['channel_address']);
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? " and ignored = " . intval($_REQUEST['ignored']) . " " : '';
    if (argc() > 1) {
        if (argc() > 2 && argv(1) == 'event') {
            $mode = 'edit';
            $event_id = argv(2);
        }
        if (argc() > 2 && argv(1) === 'add') {
            $mode = 'add';
            $item_id = intval(argv(2));
        }
        if (argc() > 2 && argv(1) === 'drop') {
            $mode = 'drop';
            $event_id = argv(2);
        }
        if (argv(1) === 'new') {
            $mode = 'new';
            $event_id = '';
        }
        if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
            $mode = 'view';
            $y = intval(argv(1));
            $m = intval(argv(2));
        }
    }
    if ($mode === 'add') {
        event_addtocal($item_id, local_channel());
        killme();
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        $export = false;
        if (argc() === 4 && argv(3) === 'export') {
            $export = true;
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if (argv(1) === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
        } else {
            // fixed an issue with "nofinish" events not showing up in the calendar.
            // There's still an issue if the finish date crosses the end of month.
            // Noting this for now - it will need to be fixed here and in Friendica.
            // Ultimately the finish date shouldn't be involved in the query.
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                              from event left join item on event_hash = resource_id \n\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored}\n\t\t\t\tAND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if ($r) {
            xchan_query($r);
            $r = fetch_post_tags($r, true);
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if ($r) {
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                // FIXME
                $edit = $rr['item_flags'] & ITEM_WALL ? array($a->get_baseurl() . '/events/event/' . $rr['event_hash'], t('Edit event'), '', '') : null;
                $drop = array($a->get_baseurl() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
            }
        }
        if ($export) {
            header('Content-type: text/calendar');
            header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
            echo ical_wrapper($r);
            killme();
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            $tpl = get_markup_template("events-js.tpl");
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array($a->get_baseurl() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'drop' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if ($r) {
            $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
            if ($r) {
                $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                info(t('Event removed') . EOL);
            } else {
                notice(t('Failed to remove event') . EOL);
            }
            goaway(z_root() . '/events');
        }
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    $channel = $a->get_channel();
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['description'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
        $mid = x($orig_event) ? $orig_event['mid'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($orig_event['event_xchan']) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $stext = datetime_convert('UTC', $tz, $sdt);
        $stext = substr($stext, 0, 14) . "00:00";
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $ftext = datetime_convert('UTC', $tz, $fdt);
        $ftext = substr($ftext, 0, 14) . "00:00";
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $catsenabled = feature_enabled(local_channel(), 'categories');
        $category = '';
        if ($catsenabled && x($orig_event)) {
            $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
            $itm = fetch_post_tags($itm);
            if ($itm) {
                $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                foreach ($cats as $cat) {
                    if (strlen($category)) {
                        $category .= ', ';
                    }
                    $category .= $cat['term'];
                }
            }
        }
        require_once 'include/acl_selectors.php';
        $perm_defaults = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$category' => $category, '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, '$required' => ' <span class="required" title="' . t('Required') . '">*</span>', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.')), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:'), '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$permissions' => t('Permissions'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false), '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #6
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 1) {
        $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
    }
    if ($a->argc > 2 && $a->argv[1] === 'ignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->argc > 2 && $a->argv[1] === 'unignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->theme_events_in_profile) {
        nav_set_selected('home');
    } else {
        nav_set_selected('events');
    }
    $editselect = 'none';
    if (feature_enabled(local_user(), 'richtext')) {
        $editselect = 'textareas';
    }
    // First day of the week (0 = Sunday)
    $firstDay = get_pconfig(local_user(), 'system', 'first_day_of_week');
    if ($firstDay === false) {
        $firstDay = 0;
    }
    $i18n = array("firstDay" => $firstDay, "Sun" => t("Sun"), "Mon" => t("Mon"), "Tue" => t("Tue"), "Wed" => t("Wed"), "Thu" => t("Thu"), "Fri" => t("Fri"), "Sat" => t("Sat"), "Sunday" => t("Sunday"), "Monday" => t("Monday"), "Tuesday" => t("Tuesday"), "Wednesday" => t("Wednesday"), "Thursday" => t("Thursday"), "Friday" => t("Friday"), "Saturday" => t("Saturday"), "Jan" => t("Jan"), "Feb" => t("Feb"), "Mar" => t("Mar"), "Apr" => t("Apr"), "May" => t("May"), "Jun" => t("Jun"), "Jul" => t("Jul"), "Aug" => t("Aug"), "Sep" => t("Sept"), "Oct" => t("Oct"), "Nov" => t("Nov"), "Dec" => t("Dec"), "January" => t("January"), "February" => t("February"), "March" => t("March"), "April" => t("April"), "May" => t("May"), "June" => t("June"), "July" => t("July"), "August" => t("August"), "September" => t("September"), "October" => t("October"), "November" => t("November"), "December" => t("December"), "today" => t("today"), "month" => t("month"), "week" => t("week"), "day" => t("day"));
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$i18n' => $i18n, '$editselect' => $editselect));
    $etpl = get_markup_template('event_end.tpl');
    $a->page['end'] .= replace_macros($etpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $editselect));
    $o = "";
    // tabs
    if ($a->theme_events_in_profile) {
        $tabs = profile_tabs($a, True);
    }
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? intval($_REQUEST['ignored']) : 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d and event.ignore = %d\n\t\t\t\tAND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')\n\t\t\t\tOR  (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')) ", intval(local_user()), intval($ignored), dbesc($start), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            //			if (get_config('experimentals','new_calendar')==1){
            $tpl = get_markup_template("events-js.tpl");
            //			} else {
            //				$tpl = get_markup_template("events.tpl");
            //			}
        }
        // Get rid of dashes in key names, Smarty3 can't handle them
        foreach ($events as $key => $event) {
            $event_item = array();
            foreach ($event['item'] as $k => $v) {
                $k = str_replace('-', '_', $k);
                $event_item[$k] = $v;
            }
            $events[$key]['item'] = $event_item;
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid or $mode !== 'new') {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        require_once 'include/acl_selectors.php';
        if ($mode === 'new') {
            $acl = $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user);
        }
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$acl' => $acl, '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #7
0
<?
session_start();

$ROOT = $_SERVER['DOCUMENT_ROOT'];
require_once $ROOT . '/helpers/database.php';
require_once $ROOT . '/helpers/templater.php';

$stylesheet = '<link href="static/css/allmeetings.css" rel="stylesheet">';

if (isset($_GET['room_name'])) {
	$last_updated = fileatime($ROOT . '/last_updated/' . str_replace(' ', '_', $_GET['room_name']));
	$templater = new Templater;
	$templater->title = $_GET['room_name'];
	$templater->meetings = sort_by_date(extract_meetings($_GET['room_name'], true));
	$templater->last_updated = utf8_encode(strftime('%A %d. %B kl %H:%M', strtotime(date('Ymd Hi', $last_updated))));
	$templater->extra_headers = array($stylesheet);

	$templater->render('allmeetingsTmpl.php');
}
else
	echo "No room name available";

function sort_by_date($meetings) {
	$sorted = array();
	foreach ($meetings as $meeting) {
		$meeting_date = date('Ymd', strtotime($meeting['start_datetime']));
		if (isset($sorted[$meeting_date]))
			$sorted[$meeting_date][] = $meeting;
		else
			$sorted[$meeting_date] = array($meeting);
	}
Beispiel #8
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
    $o = "";
    // tabs
    $tabs = profile_tabs($a, True);
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d\n\t\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                $title = strip_tags($title);
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            if (get_config('experimentals', 'new_calendar') == 1) {
                $tpl = get_markup_template("events-js.tpl");
            } else {
                $tpl = get_markup_template("events.tpl");
            }
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
        break;
}
$items = array();
$result = mysql_query("SELECT invoices.id, invoices.total, invoices.date, customer.customer_name FROM invoices, customer WHERE invoices.customer_id = customer.id AND invoices.date >= {$start_time} AND invoices.date < {$end_time} AND invoices.type = 'invoice' AND invoices.paid = 'yes';") or die(mysql_error() . '<br /><strong>YOUR QUERY:</strong><BR />' . "\n\nSELECT invoices.id, invoices.total, invoices.date, customer.customer_name FROM invoices, customer WHERE invoices.customer_id = customer.id AND invoices.date >= {$start_time} AND invoices.date < {$end_time};\n\n" . '<br />');
if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        $items[] = array('id' => $row['id'], 'date' => $row['date'], 'customer_name' => $row['customer_name'], 'amount' => $row['total']);
    }
}
$result = mysql_query("SELECT refunds.id, refunds.amount, refunds.date, customer.customer_name FROM refunds, invoices, customer WHERE refunds.invoice_id = invoices.id AND invoices.customer_id = customer.id AND refunds.date >= {$start_time} AND refunds.date < {$end_time};") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        $items[] = array('id' => $row['id'], 'date' => $row['date'], 'customer_name' => $row['customer_name'], 'amount' => $row['amount']);
    }
}
$items = sort_by_date($items);
foreach ($items as $k => $v) {
    $items[$k]['date'] = date('d/m/Y', $v['date']);
}
$result = mysql_query("SELECT MIN(date) AS date FROM invoices LIMIT 1;") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
    $row = mysql_fetch_assoc($result);
    $timeDef = $end_time - $start_time;
    $def = $lastStartTime - $row['date'];
    $pageCount = ceil($def / $timeDef) - 1;
    $pageCount = $pageCount > 0 ? $pageCount : 0;
} else {
    $pageCount = 0;
}
$response = new stdClass();
$response->response->items = $items;
Beispiel #10
0
 function get()
 {
     if (argc() > 2 && argv(1) == 'ical') {
         $event_id = argv(2);
         require_once 'include/security.php';
         $sql_extra = permissions_sql(local_channel());
         $r = q("select * from event where event_hash = '%s' {$sql_extra} limit 1", dbesc($event_id));
         if ($r) {
             header('Content-type: text/calendar');
             header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"');
             echo ical_wrapper($r);
             killme();
         } else {
             notice(t('Event not found.') . EOL);
             return;
         }
     }
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     nav_set_selected('all_events');
     if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
         $r = q("update event set dismissed = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
     }
     if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
         $r = q("update event set dismissed = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
     }
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/events', '$modparams' => 1, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $channel = \App::get_channel();
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 1) {
         if (argc() > 2 && argv(1) === 'add') {
             $mode = 'add';
             $item_id = intval(argv(2));
         }
         if (argc() > 2 && argv(1) === 'drop') {
             $mode = 'drop';
             $event_id = argv(2);
         }
         if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
             $mode = 'view';
             $y = intval(argv(1));
             $m = intval(argv(2));
         }
         if (argc() <= 2) {
             $mode = 'view';
             $event_id = argv(1);
         }
     }
     if ($mode === 'add') {
         event_addtocal($item_id, local_channel());
         killme();
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         $channel = \App::get_channel();
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
         /*
         if(x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish'];
         if(x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust'];
         if(x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary'];
         if(x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description'];
         if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location'];
         if(x($_REQUEST,'start')) $orig_event['dtstart'] = $_REQUEST['start'];
         if(x($_REQUEST,'finish')) $orig_event['dtend'] = $_REQUEST['finish'];
         if(x($_REQUEST,'type')) $orig_event['etype'] = $_REQUEST['type'];
         */
         $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
         $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
         $t_orig = x($orig_event) ? $orig_event['summary'] : '';
         $d_orig = x($orig_event) ? $orig_event['description'] : '';
         $l_orig = x($orig_event) ? $orig_event['location'] : '';
         $eid = x($orig_event) ? $orig_event['id'] : 0;
         $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
         $mid = x($orig_event) ? $orig_event['mid'] : '';
         if (!x($orig_event)) {
             $sh_checked = '';
         } else {
             $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
         }
         if ($orig_event['event_xchan']) {
             $sh_checked .= ' disabled="disabled" ';
         }
         $sdt = x($orig_event) ? $orig_event['dtstart'] : 'now';
         $fdt = x($orig_event) ? $orig_event['dtend'] : '+1 hour';
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled(local_channel(), 'categories');
         $category = '';
         if ($catsenabled && x($orig_event)) {
             $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
             $itm = fetch_post_tags($itm);
             if ($itm) {
                 $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                 foreach ($cats as $cat) {
                     if (strlen($category)) {
                         $category .= ', ';
                     }
                     $category .= $cat['term'];
                 }
             }
         }
         require_once 'include/acl_selectors.php';
         $acl = new \Zotlabs\Access\AccessList($channel);
         $perm_defaults = $acl->get();
         $permissions = x($orig_event) ? $orig_event : $perm_defaults;
         //print_r(acl2json($permissions['allow_gid'])); killme();
         $tpl = get_markup_template('event_form.tpl');
         $form = replace_macros($tpl, array('$post' => z_root() . '/events', '$eid' => $eid, '$type' => $type, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$summary' => array('summary', $event_id ? t('Edit event title') : t('Event title'), $t_orig, t('Required'), '*'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$c_text' => $event_id ? t('Edit Category') : t('Category'), '$category' => $category, '$required' => '<span class="required" title="' . t('Required') . '">*</span>', '$s_dsel' => datetimesel($f, new \DateTime(), \DateTime::createFromFormat('Y', $syear + 5), \DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), $event_id ? t('Edit start date and time') : t('Start date and time'), 'start_text', true, true, '', '', true, $first_day), '$n_text' => t('Finish date and time are not known or not relevant'), '$n_checked' => $n_checked, '$f_dsel' => datetimesel($f, new \DateTime(), \DateTime::createFromFormat('Y', $fyear + 5), \DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), $event_id ? t('Edit finish date and time') : t('Finish date and time'), 'finish_text', true, true, 'start_text', '', false, $first_day), '$nofinish' => array('nofinish', t('Finish date and time are not known or not relevant'), $n_checked, '', array(t('No'), t('Yes')), 'onclick="enableDisableFinishDate();"'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.'), array(t('No'), t('Yes'))), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => $event_id ? t('Edit Description') : t('Description'), '$d_orig' => $d_orig, '$l_text' => $event_id ? t('Edit Location') : t('Location'), '$l_orig' => $l_orig, '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$share' => array('distr', t('Share this event'), $sh_checked, '', array(t('No'), t('Yes'))), '$preview' => t('Preview'), '$perms_label' => t('Permission settings'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream')), '$allow_cid' => acl2json($permissions['allow_cid']), '$allow_gid' => acl2json($permissions['allow_gid']), '$deny_cid' => acl2json($permissions['deny_cid']), '$deny_gid' => acl2json($permissions['deny_gid']), '$submit' => t('Submit'), '$advanced' => t('Advanced Options')));
         /* end edit/create form */
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         $export = false;
         if (argc() === 4 && argv(3) === 'export') {
             $export = true;
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(1) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
         } elseif ($export) {
             $r = q("SELECT * from event where uid = %d\n\t\t\t\t\tAND (( `adjust` = 0 AND ( `dtend` >= '%s' or nofinish = 1 ) AND `dtstart` <= '%s' ) \n\t\t\t\t\tOR  (  `adjust` = 1 AND ( `dtend` >= '%s' or nofinish = 1 ) AND `dtstart` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r && !$export) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = local_channel() && $rr['author_xchan'] == get_observer_hash() ? array(z_root() . '/events/' . $rr['event_hash'] . '?expandform=1', t('Edit event'), '', '') : false;
                 $drop = array(z_root() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if ($export) {
             header('Content-type: text/calendar');
             header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
             echo ical_wrapper($r);
             killme();
         }
         if (\App::$argv[1] === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event.tpl");
         } else {
             $tpl = get_markup_template("events-js.tpl");
         }
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/events', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$view_label' => t('View'), '$month' => t('Month'), '$week' => t('Week'), '$day' => t('Day'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
     if ($mode === 'drop' && $event_id) {
         $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
         $sync_event = $r[0];
         if ($r) {
             $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
             if ($r) {
                 $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                 $sync_event['event_deleted'] = 1;
                 build_sync_packet(0, array('event' => array($sync_event)));
                 info(t('Event removed') . EOL);
             } else {
                 notice(t('Failed to remove event') . EOL);
             }
             goaway(z_root() . '/events');
         }
     }
 }