Extension:MKCalendar/mkcalendar.php

 'MKCalendar',  'author' => 'Mihály Kepler',  'url' => 'http://www.mediawiki.org/wiki/Extension:MKCalendar',  'description' => 'Calendar',  'descriptionmsg' => 'Calendar desc',  'version' => '0.9.70', );

function efMKCalendarJS { global $wgOut, $wgScriptPath, $wgJsMimeType; $wgOut->addScript(' '); $wgOut->addScript(' '); $wgOut->addScript('');

return; }

require_once("$IP/extensions/mkcalendar/mkcalendar.i18n.php"); require_once("$IP/extensions/mkcalendar/mkcalendarMysql.php");

$mkc_language="hu"; //$mkc_language=$wgUserLanguage; //$mkc_language=$wgLang; $mkimgpath="/mediawiki/extensions/mkcalendar";

function efMKCalendarInit { global $wgParser; $wgParser->setHook( 'mkcalendar', 'efMKCalendar' ); return true; }

//********************************************************************************* //********************************************************************************* //*********************************************************************************

function efMKCalendar( $input, $args, &$parser ) { global $wgOut, $wgUser, $wgScriptPath; $parser->disableCache; $retval = ""; $paramsw = split("\n",$input); $params = array; foreach($paramsw as $p ){ $paramst = split("=", $p); if ( $paramst[0] != ""){ $params[ $paramst[0] ] = $paramst[1]; } }  $mode = $params["view"]; if ( isset($params["fuser"]) and $params["view"]!="" ){ $user = $params["fuser"]; } else { $user = $wgUser->getName; } $group=$params["group"]; if ( libras( $wgUser->getName ) ){ $_SESSION['wsMKCalendar'] = "logedin"; if ($group == "resources") { $users = getuser ( $group ); $resources = getuser ( 'everyone' ); } else { $users = getuser ( $group ); $resources = getuser ( 'resources' ); }   $retval .= mkc_base( $user, $mode, $users, $resources, $group ); } return $retval; }

function libras ( $u ){ $retval = false; $tomb = mkc_get_events_to_array( "user_name",                                  "user, mkcalendar_groups",                                   " where user_email != '' and ".                                   " mkcalendar_groups.group='everyone' and ".                                   " mkcalendar_groups.user=user.user_name and ".                                   " mkcalendar_groups.user='$u' ".                                   " group by user.user_name",                                   " order by user_name " ); if( $tomb[0][0] == $u ){ $retval=true; } return $retval; }

//váz html és java body deklarációk kiírása function mkc_base ( $u, $m, $s, $r, $g ){ global $mkmessages, $mkc_language, $wgUser, $wgTitle; $retval = ""; $retval .= ''."\n". ' '."\n". " \n". "...\n". " \n"; $retval .= ''."\n". ''."\n". ' '."\n"; return $retval; }

function getuser ( $group ){ $tomb = array; $retval=''; $tomb = mkc_get_events_to_array( "user",                                  "user, mkcalendar_groups",                                   " where user_email != '' and ".                                   "mkcalendar_groups.group='$group' ".                                   "group by user",                                   " order by user " ); foreach( $tomb as $k){ if ( $retval=='' ){ $retval .= $k[0]; } else { $retval .= "--".$k[0]; } }

return $retval; }

function mkc_gen_add_jsrow( $u, $m, $g ){ global $wgUser; $retval =''; $hetfodiff = 1 - date("N"); $cmonday = mktime(0, 0, 0, date("m") , date("d")+$hetfodiff, date("Y")); $csunday = mktime(0, 0, 0, date("m", $cmonday) , date("d", $cmonday) + 6, date("Y", $cmonday)); $tombe1 = array; $tombe2 = array; switch ( $m ) { case "month": $firstday = mktime(0, 0, 0, date("m"), 1, date("Y")); $lastday = mktime(0, 0, 0, date("m")+1, 0, date("Y")); $tol = date("Y-m-d 00:00:00", $firstday); $ig = date("Y-m-d 23:59:59", $lastday ); break; case "events": $tol = date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d"), date("Y")) ); $ig = date("Y-m-d 23:59:59", mktime(0, 0, 0, date("m") , date("d")+30, date("Y")) ); $tombe1=mkc_get_events_to_array( "id, user, 'Privát', whento, whenyet, erepeat, 'Privát', 'Privát', remainder, remainderm, shared, updater, updated, '0'",                                "mkcalendar",                                 " WHERE (whento >= '$tol' and whenyet <= '$ig') and ".                                        "user!='".$u."' and shared='private' ",                                  "order by whento" ); $tombe2 = mkc_get_events_to_array( "id, user, what, whento, whenyet, erepeat, ewhere, description, remainder, remainderm, shared, updater, updated, '0'",                                  "mkcalendar",                                   " WHERE (whento >= '$tol' and whenyet <= '$ig') and ".                                          "user!='$u' and shared!='private' ",                                   "order by whento" ); break; case "groupevents": $tol = date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d"), date("Y")) ); $ig = date("Y-m-d 23:59:59", mktime(0, 0, 0, date("m") , date("d")+30, date("Y")) ); $tombe1=mkc_get_events_to_array( "id, mkcalendar.user, 'Privát', whento, whenyet, erepeat, 'Privát', 'Privát', remainder, remainderm, shared, updater, updated, '0'",                                "mkcalendar, mkcalendar_groups",                                 " WHERE (whento >= '$tol' and whenyet <= '$ig') and ".                                        "mkcalendar.user!='".$u."' and shared='private' and mkcalendar.user=mkcalendar_groups.user and ".                                        "mkcalendar_groups.group='$g' ",                                  "order by whento" ); $tombe2 = mkc_get_events_to_array( "id, mkcalendar.user, what, whento, whenyet, erepeat, ewhere, description, remainder, remainderm, shared, updater, updated, '0'",                                  "mkcalendar, mkcalendar_groups",                                   " WHERE (whento >= '$tol' and whenyet <= '$ig') and ".                                          "mkcalendar.user=mkcalendar_groups.user and ".                                          "mkcalendar_groups.group='$g' and shared!='private' ",                                   "order by whento" ); break; case "week": $tol = date("Y-m-d 00:00:00", $cmonday ); $ig = date("Y-m-d 23:59:59", $csunday ); break; default: $tol = date("Y-m-d 00:00:00", $cmonday ); $ig = date("Y-m-d 23:59:59", $csunday ); } //$tomb = mkc_get_events_to_array( $cmonday, $csunday ); $tomb1 = mkc_get_events_to_array( "id, user, what, whento, whenyet, erepeat, ewhere, description, ".                                   "remainder, remainderm, shared, updater, updated, '0'",                                    "mkcalendar",

" WHERE ". "( ".                                   "( whento >= '$tol' and whenyet <= '$ig' ) or ".                                    "( whento >= '$tol' and whento <= '$ig' and whenyet > '$ig' ) or ".                                    "( whenyet >= '$tol' and whenyet <= '$ig' and whento < '$tol' ) ".                                    ") ". "and erepeat = 'doesnotrepeat' ". "and user='$u' ",

"order by whento" );

$tomb2 = mkc_get_events_to_array( "mkcalendar.id, mkcalendar.user, what, whento, whenyet, erepeat, ewhere, description, remainder, remainderm, shared, updater, mkcalendar.updated, '1'",                                "mkcalendar, mkcalendar_shares",                                 " WHERE (whento >= '$tol' and whenyet <= '$ig') and ".                                        "mkcalendar.id = mkcalendar_shares.id and ".                                        "mkcalendar.user != '$u' and ".                                        "mkcalendar_shares.user='$u'",                                  "group by mkcalendar.id order by whento" ); //daily, weekday, weekly $tomb_dailys = mkc_get_events_to_array( "id, user, what, whento, whenyet, erepeat, ewhere, ".                                       "description, remainder, remainderm, shared, updater, updated, '0'",                                   "mkcalendar",                                   "WHERE ( erepeat = 'daily' or ". "erepeat = 'weekday' or ". "erepeat = 'weekly' ) and ".                                  "user='$u' ",                                   "order by whento" ); //monthly, yearly $tol2 = date("md", $cmonday ); $ig2 = date("md", $csunday ); $tomb_monthlys = mkc_get_events_to_array( "id, user, what, whento, whenyet, erepeat, ewhere, ".                                       "description, remainder, remainderm, shared, updater, updated, '0'",                                   "mkcalendar",                                   "WHERE ( erepeat = 'monthly' or ". "erepeat = 'yearly' ) and ".                                  "date_format(whento, '%m%d') >= '$tol2' and ".                                   "date_format(whento, '%m%d') <= '$ig2' and " .                                   //"whento >= '$tol' and ".                                   //"whenyet <= '$ig' and ".                                   "user='$u' ",                                   "order by whento"); $tomb = array_merge($tombe1, $tombe2, $tomb1, $tomb2, $tomb_dailys, $tomb_monthlys); //rakjuk sorba a $tomb -ot foreach ($tomb as $key => $row) { $swhen[$key] = $row[3]; $suser[$key] = $row[1]; } if ( count($tomb) > 1 ){ array_multisort($swhen, SORT_ASC, $suser, SORT_ASC, $tomb); } $retval .= mkc_gen_add_jsrow_print( $tomb ); return $retval; }

function mkc_gen_add_jsrow_print( $t ) { $retval =''; for ($i=0; $i<count($t); $i++){ $guests=mkc_getguests( $t[$i][0] ); $retval .= "mcal.addevent('".$t[$i][0]."', ".                            "'".$t[$i][1]."', ".                             "'".addslashes($t[$i][2])."', ".                             "'".$t[$i][3]."', ".                             "'".$t[$i][4]."', ".                             "'".$t[$i][5]."', ".                             "'".addslashes($t[$i][6])."', ".                             "'".addslashes($t[$i][7])."', ".                             "'".$t[$i][8]."', ".                             "'".$t[$i][9]."', ".                             "'".$t[$i][10]."', ".                             "'".$t[$i][11]."', ".                             "'".$t[$i][12]."', ".                             "'".$t[$i][13]."' ".                             " );\n"; for ( $j=0; $j<count($guests); $j++ ){ $retval .= "mcal.mkcEvents[$i].addguests('".$guests[$j][0]."', ".                                             "'".$guests[$j][1]."', ".                                              "'".$guests[$j][2]."', ".                                              "'".$guests[$j][3]."' ".                                              ");\n"; } }  return $retval; }

function aRepEnterBr ($s) { $retval = ereg_replace("\r\n"," ",$s); $retval = ereg_replace("\"","\'\'",$retval); return $retval; }

?>