Example #1
0
function go_update_uid()
{
    global $xoopsDB;
    $sql = "ALTER TABLE `" . $xoopsDB->prefix("tad_cal_event") . "` CHANGE `uid` `uid` mediumint(8) unsigned NOT NULL default 0";
    $xoopsDB->queryF($sql) or web_error($sql);
    return true;
}
Example #2
0
function tad_cal_list($options)
{
    global $xoopsDB, $xoopsUser, $xoopsTpl;
    include_once XOOPS_ROOT_PATH . "/modules/tad_cal/function_block.php";
    //取得目前使用者可讀的群組
    $ok_cate_arr = chk_tad_cal_cate_power('enable_group');
    $all_ok_cate = implode(",", $ok_cate_arr);
    $and_ok_cate = empty($all_ok_cate) ? "and cate_sn='0'" : "and cate_sn in({$all_ok_cate})";
    $and_ok_cate2 = empty($all_ok_cate) ? "and a.sn='0'" : "and b.cate_sn in({$all_ok_cate})";
    $even_start = date("Y-m-d 00:00:00");
    $even_end = date("Y-m-d 23:59:59", strtotime("+{$options[0]} days"));
    //抓出事件
    $sql = "select * from " . $xoopsDB->prefix("tad_cal_event") . " where `start` >= '{$even_start}' and `end` <= '{$even_end}' {$and_ok_cate} order by `start` , `sequence`";
    //die($sql);
    $result = $xoopsDB->query($sql) or web_error($sql);
    $i = 0;
    $all_event = "";
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        if (!empty($recurrence)) {
            continue;
        }
        $start = substr($start, 0, 10);
        $all_event[$start][$sn] = $title;
    }
    //抓出重複事件
    $sql = "select a.*,b.title,b.cate_sn from " . $xoopsDB->prefix("tad_cal_repeat") . " as a join " . $xoopsDB->prefix("tad_cal_event") . " as b on a.sn=b.sn where a.`start` >= '{$even_start}' and a.`end` <= '{$even_end}' {$and_ok_cate2} order by a.`start`";
    //die($sql);
    $result = $xoopsDB->queryF($sql) or web_error($sql);
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        $start = substr($start, 0, 10);
        $all_event[$start][$sn] = $title;
    }
    $content = $event = "";
    $i = 0;
    if (is_array($all_event)) {
        foreach ($all_event as $start => $arr) {
            $j = 0;
            foreach ($arr as $sn => $title) {
                $event[$j]['sn'] = $sn;
                $event[$j]['title'] = $title;
                $j++;
            }
            $content[$i]['start'] = $start;
            $content[$i]['event'] = $event;
            $event = "";
            $i++;
        }
    }
    $block['content'] = $content;
    return $block;
}
Example #3
0
function import_google($cate_sn = "")
{
    global $xoopsDB, $xoopsUser;
    if (!ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $client_id = '254265660934-4m4mon8fms910dokh93o3spp77k0ahtr.apps.googleusercontent.com';
    //$client_secret = '0ROGDfIJB1Q3RBFioMc0Bqig';
    $client_secret = '*****@*****.**';
    $redirect_uri = XOOPS_URL . '/modules/tad_cal/admin/import.php';
    include XOOPS_ROOT_PATH . '/modules/tad_cal/class/gapi/autoload.php';
    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    // $client->setAccessType('offline');
    // $client->setApprovalPrompt('force');
    $client->setScopes("https://www.googleapis.com/auth/userinfo.email");
    $client->setScopes("https://www.googleapis.com/auth/userinfo.profile");
    $client->setScopes("https://www.googleapis.com/auth/calendar");
    // $client->setScopes("https://www.googleapis.com/auth/calendar.readonly");
    $client->setApplicationName("Tad Cal");
    $client->setDeveloperKey('AIzaSyCk7fQpA3WRB3NtyYFTxrGB9wu484qDdsY');
    if (!isset($_SESSION['import_google'])) {
        $_SESSION['import_google'] = $cate_sn;
    } else {
        $cate_sn = $_SESSION['import_google'];
    }
    $cal = new Google_Service_Calendar($client);
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $_SESSION['token'] = $client->getAccessToken();
        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL) . "?cate_sn={$cate_sn}");
        exit;
    }
    if (isset($_SESSION['token'])) {
        // if($client->isAccessTokenExpired()) {
        //   $authUrl = $client->createAuthUrl();
        //   header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
        //   exit;
        // }
        $client->setAccessToken($_SESSION['token']);
    }
    if ($client->getAccessToken()) {
        //取得使用者編號
        $uid = $xoopsUser ? $xoopsUser->getVar('uid') : "";
        $sql = "select * from " . $xoopsDB->prefix("tad_cal_cate") . " where cate_sn='{$cate_sn}'";
        $result = $xoopsDB->queryF($sql) or web_error($sql);
        $all = $xoopsDB->fetchArray($result);
        //以下會產生這些變數: $cate_sn , $cate_title , $cate_sort , $cate_enable , $cate_handle , $enable_group , $enable_upload_group , $google_id , $google_pass
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        $myts =& MyTextSanitizer::getInstance();
        $now = date('Y-m-d H:i:s', time());
        date_default_timezone_set('Asia/Taipei');
        $calendarId = str_replace('%40', '@', $cate_handle);
        $events = $cal->events->listEvents($calendarId);
        while (true) {
            foreach ($events->getItems() as $event) {
                $title = $myts->addSlashes($event->summary);
                $start = $event->start->dateTime;
                $end = $event->end->dateTime;
                $recurrence = is_array($event->recurrence) ? $myts->addSlashes(implode('', $event->recurrence)) : '';
                $location = $myts->addSlashes($event->location);
                $kind = $myts->addSlashes($event->kind);
                $details = $myts->addSlashes($event->description);
                $etag = $myts->addSlashes($event->etag);
                $id = $myts->addSlashes($event->id);
                $sequence = $myts->addSlashes($event->sequence);
                $allday = isAllDay($start, $end);
                $sql = "insert into " . $xoopsDB->prefix("tad_cal_event") . "\n        (`title` , `start` , `end` , `recurrence` , `location` , `kind` , `details` , `etag` , `id` , `sequence` , `uid` , `cate_sn` , `allday` , `tag` , `last_update`)\n        values('{$title}' , '{$start}' , '{$end}' , '{$recurrence}' , '{$location}' , '{$kind}' , '{$details}' , '{$etag}' , '{$id}' , '{$sequence}' , '{$uid}' , '{$cate_sn}' , '{$allday}' , '{$tag}' , '{$now}') ON DUPLICATE KEY UPDATE `title`='{$title}' , `start`='{$start}' , `end`='{$end}' , `recurrence`='{$recurrence}' , `location`='{$location}' , `kind`='{$kind}' , `details`='{$details}' , `etag`='{$etag}' , `id`='{$id}' , `sequence`='{$sequence}' , `uid`= '{$uid}' , `cate_sn`='{$cate_sn}' , `allday`='{$allday}' , `tag`='{$tag}' , `last_update`='{$now}'";
                $xoopsDB->queryF($sql) or web_error($sql);
                //取得最後新增資料的流水編號
                $sn = $xoopsDB->getInsertId();
                //重複事件
                rrule($sn, $recurrence, $allday);
            }
            // $pageToken = $events->getNextPageToken();
            // if ($pageToken) {
            //   $optParams = array('pageToken' => $pageToken);
            //   $events = $cal->events->listEvents($calendarId, $optParams);
            // } else {
            //   break;
            // }
        }
        $now = date("Y-m-d H:i:s");
        $sql = "delete from " . $xoopsDB->prefix("tad_cal_event") . " where cate_sn='{$cate_sn}' and `last_update` < '{$now}'";
        $xoopsDB->queryF($sql) or web_error($sql);
        if (isset($_SESSION['import_google'])) {
            unset($_SESSION['import_google']);
        }
    } else {
        $authUrl = $client->createAuthUrl();
        header("Location: " . $authUrl);
        exit;
    }
}
Example #4
0
function get_event()
{
    global $xoopsDB, $xoopsUser, $xoopsModuleConfig;
    $cate_sn = intval($_REQUEST['cate_sn']);
    //取得目前使用者可讀的群組
    $ok_cate_arr = chk_tad_cal_cate_power('enable_group');
    $all_ok_cate = implode(",", $ok_cate_arr);
    $and_ok_cate = empty($all_ok_cate) ? "and cate_sn='0'" : "and cate_sn in({$all_ok_cate})";
    $and_ok_cate2 = empty($all_ok_cate) ? "and a.sn='0'" : "and b.cate_sn in({$all_ok_cate})";
    $even_start = date("Y-m-d H:i", $_REQUEST['start'] / 1000);
    $even_end = $_REQUEST['end'] == "0000-00-00 00:00" ? "" : date("Y-m-d H:i", $_REQUEST['end'] / 1000);
    $and_cate_sn = empty($cate_sn) ? "" : "and `cate_sn` = '{$cate_sn}'";
    $and_cate_sn2 = empty($cate_sn) ? "" : "and b.`cate_sn` = '{$cate_sn}'";
    //抓出事件
    $sql = "select * from " . $xoopsDB->prefix("tad_cal_event") . " where `start` >= '{$even_start}' and `end` <= '{$even_end}' {$and_ok_cate} {$and_cate_sn} order by `start` , `sequence`";
    //die($sql);
    $result = $xoopsDB->query($sql) or web_error($sql);
    $i = 0;
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        if (!empty($recurrence)) {
            continue;
        }
        $allDay = $allday == '1' ? true : false;
        //正確顯示行事曆事件條
        $startTime = userTimeToServerTime(strtotime($start));
        $endTime = userTimeToServerTime(strtotime($end));
        if (empty($endTime)) {
            $endTime = $startTime + 86400;
        }
        //計算應顯示數字用
        $day = ceil(($endTime - $startTime) / 86400);
        if (empty($day)) {
            $day = 1;
        }
        $start = date('Y-m-d H:i', $startTime);
        $end = date('Y-m-d H:i', $endTime);
        if ($allDay) {
            $endTime = strtotime($end) - 86400;
        }
        //避免截掉半個中文字
        $title_num = $xoopsModuleConfig['title_num'] * 3 * $day;
        $event_title = xoops_substr(strip_tags($title), 0, $title_num);
        $myEvents[$i]['id'] = $sn;
        $myEvents[$i]['title'] = "{$event_title}";
        //$myEvents[$i]['url']="event.php?sn=$sn";
        $myEvents[$i]['rel'] = XOOPS_URL . "/modules/tad_cal/event.php?op=view&sn={$sn}";
        $myEvents[$i]['start'] = $startTime;
        if (!empty($end)) {
            $myEvents[$i]['end'] = $endTime;
        }
        $myEvents[$i]['allDay'] = $allDay;
        $myEvents[$i]['className'] = "my{$cate_sn}";
        $i++;
    }
    //抓出重複事件
    $sql = "select a.*,b.title,b.cate_sn from " . $xoopsDB->prefix("tad_cal_repeat") . " as a join " . $xoopsDB->prefix("tad_cal_event") . " as b on a.sn=b.sn where a.`start` >= '{$even_start}' and a.`end` <= '{$even_end}' {$and_ok_cate2} {$and_cate_sn2} order by a.`start`";
    //die($sql);
    $result = $xoopsDB->queryF($sql) or web_error($sql);
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        $allDay = $allday == '1' ? true : false;
        //正確顯示行事曆事件條
        $DBstartTime = strtotime($start);
        $startTime = userTimeToServerTime(strtotime($start));
        $endTime = userTimeToServerTime(strtotime($end));
        if (empty($endTime)) {
            $endTime = $startTime + 86400;
        }
        //計算應顯示數字用
        $day = ceil(($endTime - $startTime) / 86400);
        if (empty($day)) {
            $day = 1;
        }
        $start = date('Y-m-d H:i', $startTime);
        $end = date('Y-m-d H:i', $endTime);
        if ($allDay) {
            $endTime = strtotime($end) - 86400;
        }
        //避免截掉半個中文字
        $title_num = $xoopsModuleConfig['title_num'] * 3 * $day;
        //if(empty($title_num))$title_num=21;
        $event_title = xoops_substr(strip_tags($title), 0, $title_num);
        $myEvents[$i]['id'] = $sn;
        $myEvents[$i]['title'] = "* {$event_title}";
        //$myEvents[$i]['url']="event.php?sn=$sn&stamp=$startTime";
        $myEvents[$i]['rel'] = XOOPS_URL . "/modules/tad_cal/event.php?op=view&sn={$sn}&stamp={$DBstartTime}";
        $myEvents[$i]['start'] = $startTime;
        if (!empty($end)) {
            $myEvents[$i]['end'] = $endTime;
        }
        $myEvents[$i]['allDay'] = $allDay;
        $myEvents[$i]['className'] = "my{$cate_sn}";
        $i++;
    }
    return json_encode($myEvents);
}
Example #5
0
        ${$k} = $v;
    }
    if (!empty($recurrence)) {
        continue;
    }
    $start = substr($start, 0, 10);
    if ($_POST['show_type'] == "separate") {
        $all_event[$start][$cate_sn][$sn] = $title;
    } else {
        $all_event[$start][$sn] = $title;
    }
}
//抓出重複事件
$sql = "select a.*,b.title,b.cate_sn from " . $xoopsDB->prefix("tad_cal_repeat") . " as a join " . $xoopsDB->prefix("tad_cal_event") . " as b on a.sn=b.sn where a.`start` >= '{$even_start}' and a.`end` <= '{$even_end}' {$and_ok_cate2}  order by a.`start`";
//die($sql);
$result = $xoopsDB->queryF($sql) or web_error($sql);
while ($all = $xoopsDB->fetchArray($result)) {
    //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
    foreach ($all as $k => $v) {
        ${$k} = $v;
    }
    $start = substr($start, 0, 10);
    if ($_POST['show_type'] == "separate") {
        $all_event[$start][$cate_sn][$sn] = $title;
    } else {
        $all_event[$start][$sn] = $title;
    }
}
//die(var_export($all_event));
if ($_POST['dl_type'] == "all_week") {
    //周簡曆
Example #6
0
function get_event_title($start = "")
{
    global $xoopsDB, $xoopsUser, $xoopsConfig;
    //取得目前使用者可讀的群組
    $ok_cate_arr = chk_tad_cal_cate_power('enable_group');
    $all_ok_cate = implode(",", $ok_cate_arr);
    $and_ok_cate = empty($all_ok_cate) ? "and cate_sn='0'" : "and cate_sn in({$all_ok_cate})";
    $and_ok_cate2 = empty($all_ok_cate) ? "and a.sn='0'" : "and b.cate_sn in({$all_ok_cate})";
    setTimezoneByOffset($xoopsConfig['default_TZ']);
    $even_start = date("Y-m-d 00:00:00", $start / 1000);
    $even_end = date("Y-m-d 23:59:59", $start / 1000);
    //抓出事件
    $sql = "select * from " . $xoopsDB->prefix("tad_cal_event") . " where ((`start` >= '{$even_start}' and `start` <= '{$even_end}') or (`end` > '{$even_start}' and `end` <= '{$even_end}')) {$and_ok_cate} order by `start` , `sequence`";
    //die($sql);
    $result = $xoopsDB->query($sql) or web_error($sql);
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        if (!empty($recurrence)) {
            continue;
        }
        $title_arr[$sn] = $title;
    }
    //抓出重複事件
    $sql = "select a.*,b.title,b.cate_sn from " . $xoopsDB->prefix("tad_cal_repeat") . " as a join " . $xoopsDB->prefix("tad_cal_event") . " as b on a.sn=b.sn where ((a.`start` >= '{$even_start}' and a.`start` <= '{$even_end}') or (a.`end` > '{$even_start}' and a.`end` <= '{$even_end}')) {$and_ok_cate2} order by a.`start`";
    //die($sql);
    $result = $xoopsDB->queryF($sql) or web_error($sql);
    while ($all = $xoopsDB->fetchArray($result)) {
        //以下會產生這些變數: $sn , $title , $start , $end , $recurrence , $location , $kind , $details , $etag , $id , $sequence , $uid , $cate_sn
        foreach ($all as $k => $v) {
            ${$k} = $v;
        }
        $title_arr[$sn] = $title;
    }
    $all = "\n  <ul>";
    foreach ($title_arr as $sn => $title) {
        $all .= "<li><a href='" . XOOPS_URL . "/modules/tad_cal/event.php?sn={$sn}' style='text-decoration:none;color:#202020;'>{$title}</a></li>";
    }
    $all .= "</ul>";
    return $all;
}
Example #7
0
function get_cal_array()
{
    global $xoopsDB;
    $sql = "select cate_sn,cate_title from " . $xoopsDB->prefix("tad_cal_cate") . "";
    $result = $xoopsDB->queryF($sql) or web_error($sql);
    while (list($cate_sn, $cate_title) = $xoopsDB->fetchRow($result)) {
        $arr[$cate_sn] = $cate_title;
    }
    return $arr;
}
Example #8
0
 function rrule($sn = '', $recurrence = '', $allDay = null)
 {
     global $xoopsDB, $xoopsUser;
     include_once XOOPS_ROOT_PATH . "/modules/tad_cal/class/rrule.php";
     include_once XOOPS_ROOT_PATH . "/modules/tad_cal/class/ical.php";
     if (empty($sn) or empty($recurrence)) {
         return;
     }
     // die($recurrence);
     $ical = new ical();
     $ical->parse($recurrence);
     $rrule_array = $ical->get_all_data();
     // die('[rrule_array]' . var_export($rrule_array));
     foreach ($rrule_array['']['RRULE'] as $key => $val) {
         $all[] = "{$key}={$val}";
     }
     $rrule = 'RRULE:' . implode(";", $all);
     // die($rrule_array['']['DTSTART']['unixtime']);
     $start = substr(str_replace(":", "", str_replace("-", "", date("c", $rrule_array['']['DTSTART']['unixtime']))), 0, 15);
     $endTime = $rrule_array['']['DTEND']['unixtime'] - $rrule_array['']['DTSTART']['unixtime'];
     // die($start . "====" . $rrule);
     // echo "<p>start= $start</p>";
     // echo "<p>rrule= $rrule</p>";
     $rule = new RRule($start, $rrule);
     $i = 0;
     while ($date = $rule->GetNext()) {
         if ($i > 300) {
             break;
         }
         $new_date = $date->Render();
         // echo "<p>new_date= $new_date</p>";
         if (empty($new_date)) {
             continue;
         }
         $end = date("Y-m-d H:i", strtotime($new_date) + $endTime);
         $allday = is_null($allDay) ? isAllDay($new_date, $end) : $allDay;
         $allDate[] = "('{$sn}','{$new_date}','{$end}','{$allday}')";
         $i++;
     }
     // exit;
     $sql_data = implode(",", $allDate);
     if (empty($sql_data)) {
         return;
     }
     $sql = "delete from " . $xoopsDB->prefix("tad_cal_repeat") . " where `sn`='{$sn}'";
     $xoopsDB->queryF($sql) or web_error($sql);
     $sql = "insert into " . $xoopsDB->prefix("tad_cal_repeat") . "\n        (`sn` , `start` , `end` , `allday`)\n        values{$sql_data}";
     // echo "<p>$sql</p>";
     $xoopsDB->queryF($sql) or web_error($sql);
 }
Example #9
0
function tad_cal_all_sync()
{
    global $xoopsDB, $xoopsModule;
    $sql = "select cate_sn from " . $xoopsDB->prefix("tad_cal_cate") . " where `cate_handle`!=''";
    $result = $xoopsDB->query($sql) or web_error($sql);
    while (list($cate_sn) = $xoopsDB->fetchRow($result)) {
        import_google($cate_sn);
    }
}