public function mwCalendar($params)
 {
     global $wgOut, $wgTitle, $wgScript, $wgScriptPath, $IP;
     $this->setDefaults($params);
     ## RUN FIRST ##
     helpers::debug("******** Calendar Init()-{$this->key} ******** ");
     $list = '';
     $rteJS = '';
     // set the calendar's initial date
     $now = $this->now = getdate();
     $this->month = $now['mon'];
     $this->year = $now['year'];
     $this->day = $now['mday'];
     ## load normal calendar
     $cookie_name = helpers::cookie_name($this->key);
     helpers::debug('Checking for cookie: ' . $cookie_name);
     if (isset($_COOKIE[$cookie_name])) {
         $date = getdate($_COOKIE[$cookie_name]);
         //timestamp value
         $this->month = $date['mon'];
         $this->year = $date['year'];
         helpers::debug("Coookie found ({$cookie_name}), SETTING calendar date/time: {$this->month}/{$this->year}");
     }
     $this->title = $wgScript . '?title=' . $wgTitle->getPrefixedText();
     $this->db = new CalendarDatabase();
     $this->db->validateVersion();
     //make sure db and files match
     $this->options = $this->db->getOptions($this->calendarName);
     ## this basically calls a function that evaluates $_POST[] events (new, delete, cancel, etc)
     ## no need to do anything else in the calendar until any db updates have completed
     if (helpers::is_my_calendar($this->key)) {
         EventHandler::CheckForEvents();
     }
     ## add any custom groups
     $arrParamsGrps = isset($params['groups']) ? explode(',', $params['groups']) : array();
     foreach ($arrParamsGrps as $grp) {
         $grpCount = count($this->db->getGroupUsers($grp));
         $list .= "<option>#{$grp} ({$grpCount} " . helpers::translate("mwc_members") . ")</option>";
     }
     /* 		$arrGroups = $this->db->getDatabaseGroups();
     		foreach($arrGroups as $grp){
     			$list .= "<option>#$grp</option>";
     		} 
     */
     ## build the mw user-list which should only be users with active email
     $arrUsers = $this->db->getDatabaseUsers();
     while (list($user, $realname) = each($arrUsers)) {
         $realname = htmlentities($realname, ENT_QUOTES);
         $list .= "<option>{$user} ({$realname})</option>";
     }
     $list = "<SELECT class=notifyselect id=selectNotify name=selectNotify size=8 onClick=selectedListItem()>" . $list . "</SELECT>";
     ## pull in all the html template forms we have
     $addEventHtml = file_get_contents(mwcalendar_base_path . "/html/AddEvent.html");
     $batchHtml = file_get_contents(mwcalendar_base_path . "/html/batchadd.html");
     $this->htmlData = file_get_contents(mwcalendar_base_path . "/html/default.html");
     $this->htmlOption = file_get_contents(mwcalendar_base_path . "/html/Options.html");
     $addEventHtml = str_replace('[[SELECT_OPTIONS]]', $list, $addEventHtml);
     ## building my own sytlesheets and javascript links...
     $stdJSArray = array('DatePicker.js', 'tabber.js', 'InvitePicker.js', 'TimePicker.js', 'common.js', 'rte.js');
     $rteExists = file_exists($IP . "/extensions/tinymce/jscripts/tiny_mce/tiny_mce.js");
     if ($this->useRTE && $rteExists) {
         $rteJS .= $this->buildJavascript(array('/extensions/tinymce/jscripts/tiny_mce/tiny_mce.js'), true);
         $rteJS .= $this->buildJavascript(array('rte.js'));
     }
     $this->stylesheet = $this->buildStylesheet(array('DatePicker.css', 'tabber.css', 'default.css'));
     $this->javascript = $this->buildJavascript(array('DatePicker.js', 'tabber.js', 'InvitePicker.js', 'TimePicker.js', 'common.js'));
     $this->javascript .= $rteJS;
     ## build the addEvent and batch tabs
     $tab1 = $this->buildTab(helpers::translate('mwc_event'), $addEventHtml);
     $tab2 = $this->buildTab(helpers::translate('mwc_batch'), $batchHtml);
     $this->tabHtml = '<div class="tabber">' . $tab1 . $tab2 . '</div>';
 }
 public static function CheckForEvents()
 {
     global $wgUser, $wgOut;
     helpers::debug('Checking for POST events');
     $db = new CalendarDatabase();
     $arr = explode('&', $_SERVER['REQUEST_URI']);
     $url = $arr[0];
     //clear any previous parameters
     // this is the active user (can be the creator... or the editor)
     $whodidit = $wgUser->getName();
     if (isset($_POST["options"])) {
         $optionURL = $url . "&Name=" . $_POST['CalendarKey'] . "&Options=true";
         header("Location: " . $optionURL);
         return;
     }
     if (isset($_POST["SaveOptions"])) {
         helpers::debug("POST: SaveOptions");
         $arrOptions = self::saveOptions();
         $db->setOptions($_POST['calendar'], $arrOptions);
     }
     // see if a new event was saved and apply changes to database
     if (isset($_POST["save"])) {
         helpers::debug("POST: Event Saved");
         $arrEvent = self::buildEventArray();
         // are we updating or creating new?
         if ($_POST['eventid']) {
             $db->updateEvent($arrEvent, $_POST['eventid']);
         } else {
             $db->setEvent($arrEvent);
         }
         if (isset($_POST["invites"])) {
             CalendarEmail::send($_POST["invites"], $arrEvent, 'save');
         }
         header("Location: " . $url);
     }
     if (isset($_POST["savebatch"])) {
         helpers::debug("POST: Batch Saved");
         self::addFromBatch($db, $whodidit);
         header("Location: " . $url);
     }
     if (isset($_POST["delete"])) {
         helpers::debug("POST: Event Deleted");
         $db->deleteEvent($_POST['eventid']);
         $arrEvent = self::buildEventArray();
         if (isset($_POST["invites"])) {
             CalendarEmail::send($_POST["invites"], $arrEvent, 'delete');
         }
         header("Location: " . $url);
     }
     if (isset($_POST["cancel"])) {
         helpers::debug("POST: Event Cancelled");
         header("Location: " . $url);
     }
     // timestamp will be populated only if any nav butten is clicked
     if (isset($_POST["timestamp"])) {
         $month = $_POST['monthSelect'];
         $year = $_POST['yearSelect'];
         if (isset($_POST['monthForward'])) {
             $month += 1;
         }
         if (isset($_POST['monthBack'])) {
             $month -= 1;
         }
         if (isset($_POST['yearForward'])) {
             $year += 1;
         }
         if (isset($_POST['yearBack'])) {
             $year -= 1;
         }
         if (isset($_POST['today'])) {
             $timestamp = time();
             //now
         } else {
             $timestamp = mktime(0, 0, 0, $month, 1, $year);
             //modified date
         }
         $cookie_name = helpers::cookie_name($_POST['CalendarKey']);
         setcookie($cookie_name, $timestamp);
         helpers::debug('Setting cookie: ' . $cookie_name);
         helpers::debug("POST: Navigation Activated: {$cookie_name}, TIMESTAMP: {$timestamp}");
         header("Location: " . $url);
     }
 }