Location: PHPKode > projects > Nuke Modules CVS > modules/PostCalendar/pnuser.php
<?php
// $Id: pnuser.php,v 1.25.2.4 2002/07/11 16:45:13 epsilon7 Exp $
/********************************************************/
/* PostCalendar                                         */
/* Version 2.6,  see changes.txt for details            */
/* Originally by Rob Sutton (Events Calendar)           */
/* Development continued by                             */
/*                                                      */
/*  The PostCalendar Development Team                   */
/*     Mahmood Al-Yousif - hide@address.com          */
/*     Craig Hamlin - hide@address.com             */
/*     HotBird - hide@address.com                        */
/*     Roger Raymond - hide@address.com                 */
/*                                                      */
/* This program is opensource so you can do whatever    */
/* you want with it. However, I'm happy about any       */
/* clever idea or nifty change you might have or have   */
/* done, send them to                                   */
/* hide@address.com                                 */
/*                                                      */
/* Any new versions can be found at                     */
/* http://www.bahraini.tv first                         */
/********************************************************/



function PostCalendar_user_main()
{
    $output = new pnHTML();
    
    if (!pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_READ)) {
        $output->Text(_POSTCALENDARNOAUTH);
        return $output->GetOutput();
    }
    
    // get the vars that were passed in
    $Date = pnVarCleanFromInput('Date');
    if(!isset($Date)) {
        //$Date = date('m/d/Y');
        $time = time();
        $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
        $Date = ml_ftime('%m/%d/%Y',$time);
    }

    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(PostCalendar_user_view(array('Date'=>$Date)));
    $output->SetInputMode(_PNH_PARSEINPUT);
    
    return $output->GetOutput();
}


/**
 * view items
 * This is a standard function to provide an overview of all of the items
 * available from the module.
 */
function PostCalendar_user_view()
{
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_OVERVIEW)) {
        $output->Text(_POSTCALENDARNOAUTH);
        return $output->GetOutput();
    }
    
    // get the vars that were passed in
    list($Date,
         $viewtype,
         $jumpday,
         $jumpmonth,
         $jumpyear) = pnVarCleanFromInput('Date',
                                          'viewtype',
                                          'jumpday',
                                          'jumpmonth',
                                          'jumpyear');
    // set up defaults
    if(!isset($viewtype)) {
        if(isset($jumpday)) {
            $viewtype = 'day';
        } else {
            // we should make this a setting in the DB
            // month, day, year, flat
            $viewtype = 'month';
        }
    }
    if(!isset($Date)) {
        if(isset($jumpday)) {
            $Date = $jumpmonth.'/'.$jumpday.'/'.$jumpyear;
        } else {
            // set it up as today
            //$Date = Date('m/d/Y');
            $time = time();
            $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
            $Date = ml_ftime('%m/%d/%Y',$time);
        }
    }

    $output = new pnHTML();
    
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(PostCalendar_usermenu(array('Date'=>$Date)));
    $output->SetInputMode(_PNH_PARSEINPUT);
    
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(PostCalendar_user_display(array('viewtype'=>$viewtype,'Date'=>$Date)));
    $output->SetInputMode(_PNH_PARSEINPUT);
    
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(PostCalendar_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

    return $output->GetOutput();
}

/**
 * display item
 * This is a standard function to provide detailed information on a single item
 * available from the module.
 */
function PostCalendar_user_display($args)
{
    list($eid,
         $viewtype,
         $Date) = pnVarCleanFromInput('eid',
                                      'viewtype',
                                      'Date');

    extract($args);

    if(empty($Date) && empty($viewtype)) {
        return false;
    }
    
    // Load the user API
    if (!pnModAPILoad('PostCalendar', 'user')) {
        die('Failed to load PostCalendar User API');
    }
    
    $output = new pnHTML();
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    
    switch ($viewtype) {
    
        case 'day':
            $output->Text(pnModAPIFunc('PostCalendar','user','buildDay',array('Date'=>$Date)));
            break;
            
        case 'week':
            $output->Text(pnModAPIFunc('PostCalendar','user','buildWeek',array('Date'=>$Date)));
            break;
            
        case 'month':
            $output->Text(pnModAPIFunc('PostCalendar','user','buildMonth',array('Date'=>$Date)));
            break;
            
        case 'year':
            $output->Text(pnModAPIFunc('PostCalendar','user','buildYear',array('Date'=>$Date)));
            break;
            
        case 'details':
            $output->Text(pnModAPIFunc('PostCalendar','user','eventDetail',array('eid'=>$eid)));
            break;
    }
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

/**
 * submit an event
 */
function PostCalendar_user_submit($args)
{   
    $output = new pnHTML();
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    
    // check permissions
    if (!pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_COMMENT)) {
        $output->Text(_POSTCALENDARNOAUTH);
        return $output->GetOutput();
    }
    
    pnThemeLoad(pnUserGetTheme());
    // get the theme globals :: is there a better way to do this?
    global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
    global $textcolor1, $textcolor2;
    $Date = pnVarCleanFromInput('Date');
    extract($args);
    if(!isset($Date)) {
        //$Date = date('m/d/Y');
        $time = time();
        $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
        $Date = ml_ftime('%m/%d/%Y',$time);
    }
    list($month,$day,$year) = explode('/',$Date);
    
    // lets get the module's information
    $modinfo = pnModGetInfo(pnModGetIDFromName('PostCalendar'));
    
    $time24hours            = pnModGetVar('PostCalendar','time24hours');
    $useinternationaldates  = pnModGetVar('PostCalendar','useinternationaldates');
    $allowdirectsubmit      = pnModGetVar('PostCalendar','allowdirectsubmit');
    $displaytopics          = pnModGetVar('PostCalendar','displaytopics');
    
    // categories - make this dynamic the next release!!!
    $category1 = pnModGetVar('PostCalendar','category1');
    $category2 = pnModGetVar('PostCalendar','category2');
    $category3 = pnModGetVar('PostCalendar','category3');
    $category4 = pnModGetVar('PostCalendar','category4');
    $category5 = pnModGetVar('PostCalendar','category5');
    
    if (!pnModAPILoad('PostCalendar', 'user')) {
        $output->Text(_PC_API_LOAD_FAILED);
        return $output->GetOutput();
    }

    // get DB information
    pnModDBInfoLoad('PostCalendar');
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    
    // link to the events tables
    $events_table = $pntable['postcalendar_events'];
    $events_column = &$pntable['postcalendar_events_column'];
    
    // main menu
    $output->Text(PostCalendar_usermenu(array('Date'=>$Date)));
    
    // are we previewing or committing the event?
    $preview = pnVarCleanFromInput('preview') ? true : false;
    $commit  = pnVarCleanFromInput('commit') ? true : false;
    
    list($event_subject,
         $event_desc,
         $event_topic,
         $event_startday,
         $event_startmonth,
         $event_startyear,
         $event_starttimeh,
         $event_starttimem,
         $event_startampm,
         $event_endday,
         $event_endmonth,
         $event_endyear,
         $event_endtimeh,
         $event_endtimem,
         $event_endampm,
         $event_location,
         $event_contname,
         $event_conttel,
         $event_contemail,
         $event_website,
         $event_fee,
         $event_recurrtype,
         $event_recurrfreq,
         $event_recurrspec,
         $event_allday,
         $event_category)= pnVarCleanFromInput('event_subject',
                                               'event_desc',
                                               'event_topic',
                                               'event_startday',
                                               'event_startmonth',
                                               'event_startyear',
                                               'event_starttimeh',
                                               'event_starttimem',
                                               'event_startampm',
                                               'event_endday',
                                               'event_endmonth',
                                               'event_endyear',
                                               'event_endtimeh',
                                               'event_endtimem',
                                               'event_endampm',
                                               'event_location',
                                               'event_contname',
                                               'event_conttel',
                                               'event_contemail',
                                               'event_website',
                                               'event_fee',
                                               'event_recurrtype',
                                               'event_recurrfreq',
                                               'event_recurrspec',
                                               'event_allday',
                                               'event_category');
    
    if (pnUserLoggedIn()) {
        $uname = pnUserGetVar('uname');
    } else {
        $uname = pnConfigGetVar('anonymous');
    }
    if(!isset($event_recurrtype)) {
        $event_recurrtype = -1;
    }
    $output->FormStart(pnModUrl('PostCalendar','user','submit'));
    $output->tabindex=1;
    
    if($preview) {
        // check for required fields
        $required_vars = array('event_subject','event_desc');
        $required_name = array(_PC_EVENT_TITLE,_PC_EVENT_DESC);
        $error_msg = '';
        $output->SetOutputMode(_PNH_RETURNOUTPUT);
        for ($r=0; $r<count($required_vars); $r++) {
            if(empty($$required_vars[$r]) || !preg_match('/\S/i',$$required_vars[$r])) {
                $error_msg .= $output->Text('<b>'.$required_name[$r].'</b> is a required field.');
                $error_msg .= $output->Linebreak(); 
            }
        }
        // check date validity
        if($time24hours) {
            $startTime = $event_starttimeh.':'.$event_starttimem;
            $endTime =   $event_endtimeh.':'.$event_endtimem;
        } else {
            if($event_startampm == _AM_VAL) {
                $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
            } else {
                $event_starttimeh =  $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
            }
            if($event_endampm == _AM_VAL) {
                $event_endtimeh = $event_endtimeh == 12 ? '00' : $event_endtimeh;
            } else {
                $event_endtimeh =  $event_endtimeh != 12 ? $event_endtimeh+=12 : $event_endtimeh;
            }
            $startTime = $event_starttimeh.':'.$event_starttimem;
            $endTime =   $event_endtimeh.':'.$event_endtimem;
        }
        $sdate = strtotime($event_startyear.'-'.$event_startmonth.'-'.$event_startday.' '.$startTime);
        $edate = strtotime($event_endyear.'-'.$event_endmonth.'-'.$event_endday.' '.$endTime);
        $tdate = strtotime(date('Y-m-d'));
        
        if($sdate < $tdate) {
            $error_msg .= $output->Text('Your start date is prior to today\'s date');
            $error_msg .= $output->Linebreak(); 
        }
        if($edate < $sdate) {
            $error_msg .= $output->Text('Your start date is greater that your end date');
            $error_msg .= $output->Linebreak(); 
        }
        if(!checkdate($event_startmonth,$event_startday,$event_startyear)) {
            $error_msg .= $output->Text('Your start date is invalid');
            $error_msg .= $output->Linebreak(); 
        }
        if(!checkdate($event_endmonth,$event_endday,$event_endyear)) {
            $error_msg .= $output->Text('Your end date is invalid'); 
            $error_msg .= $output->Linebreak();
        }
        $output->SetOutputMode(_PNH_KEEPOUTPUT);
        
        if(!empty($error_msg)) {
            $preview = false;
            $output->Text('<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">');
            $output->Text('<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">');
                $output->Text('<center><b>There are errors with your submission.  These are outlined below.</b></center>'); 
                $output->Linebreak();
                $output->Text($error_msg);
            $output->Text('</td></td></table>');
            $output->Text('</td></td></table>');
            $output->Linebreak(2);
        } else {
            $output->Text(pnModAPIFunc('PostCalendar','user','eventPreview',array('event_subject'=>$event_subject,
                                                                                  'event_desc'=>$event_desc,
                                                                                  'event_topic'=>$event_topic,
                                                                                  'event_startday'=>$event_startday,
                                                                                  'event_startmonth'=>$event_startmonth,
                                                                                  'event_startyear'=>$event_startyear,
                                                                                  'event_starttimeh'=>$event_starttimeh,
                                                                                  'event_starttimem'=>$event_starttimem,
                                                                                  'event_startampm'=>$event_startampm,
                                                                                  'event_endday'=>$event_endday,
                                                                                  'event_endmonth'=>$event_endmonth,
                                                                                  'event_endyear'=>$event_endyear,
                                                                                  'event_endtimeh'=>$event_endtimeh,
                                                                                  'event_endtimem'=>$event_endtimem,
                                                                                  'event_endampm'=>$event_endampm,
                                                                                  'event_location'=>$event_location,
                                                                                  'event_contname'=>$event_contname,
                                                                                  'event_conttel'=>$event_conttel,
                                                                                  'event_contemail'=>$event_contemail,
                                                                                  'event_website'=>$event_website,
                                                                                  'event_fee'=>$event_fee,
                                                                                  'event_recurrtype'=>$event_recurrtype,
                                                                                  'event_recurrfreq'=>$event_recurrfreq,
                                                                                  'event_recurrspec'=>$event_recurrspec,
                                                                                  'event_allday'=>$event_allday,
                                                                                  'event_category'=>$event_category,
                                                                                  'uname'=>$uname)));
            $output->Linebreak();
            $output->Text('<input type="submit" name="commit" value="'._PC_EVENT_SUBMIT.'">');
            $output->Linebreak(2);
        }
    }
    
    if($commit) {
        // 04/14/02 pascal berger: events submitted by admins are immediately approved
        if($allowdirectsubmit || pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN)) {
            $event_status = _EVENT_APPROVED;
        } else {
            $event_status = _EVENT_QUEUED;
        }
        
        // set up some vars for the insert statement
        $startDate = $event_startyear.'-'.$event_startmonth.'-'.$event_startday;
        $endDate =   $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
        
        if(!isset($event_allday)) { $event_allday = 0; }
        if($time24hours) {
            $startTime = $event_starttimeh.':'.$event_starttimem.':00';
            $endTime =   $event_endtimeh.':'.$event_endtimem.':00';
        } else {
            if($event_startampm == _AM_VAL) {
                $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
            } else {
                $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
            }
            $startTime = $event_starttimeh.':'.$event_starttimem.':00';
            if($event_endampm == _AM_VAL) {
                $event_endtimeh = $event_endtimeh == 12 ? '00' : $event_endtimeh;
            } else {
                $event_endtimeh =  $event_endtimeh != 12 ? $event_endtimeh+=12 : $event_endtimeh;
            }
            $endTime =   $event_endtimeh.':'.$event_endtimem.':00';
        }
        
        // prepare the vars for the insert statement        
        list($pevent_subject,$pevent_desc,$pevent_topic,
             $puname,$pstartDate,$pendDate,$pevent_recurrtype,
             $pevent_recurrfreq,$pstartTime,$pendTime,$pevent_allday,
             $pevent_location,$pevent_conttel,
             $pevent_contname,$pevent_contemail,$pevent_website,
             $pevent_fee,$pevent_status,$pevent_category) = pnVarPrepForStore($event_subject,$event_desc,$event_topic,
                                                                $uname,$startDate,$endDate,$event_recurrtype,
                                                                $event_recurrfreq,$startTime,$endTime,$event_allday,
                                                                $event_location,$event_conttel,
                                                                $event_contname,$event_contemail,$event_website,
                                                                $event_fee,$event_status,$event_category);
        
        
        $sql = "INSERT INTO $events_table (
                    $events_column[title],
                    $events_column[time],
                    $events_column[hometext],
                    $events_column[topic],
                    $events_column[informant],
                    $events_column[eventDate],
                    $events_column[endDate],
                    $events_column[recurrtype],
                    $events_column[recurrfreq],
                    $events_column[startTime],
                    $events_column[endTime],
                    $events_column[alldayevent],
                    $events_column[barcolor],
                    $events_column[location],
                    $events_column[conttel],
                    $events_column[contname],
                    $events_column[contemail],
                    $events_column[website],
                    $events_column[fee],
                    $events_column[eventstatus])
                VALUES ('$pevent_subject', 
                        NOW(),
                        '$pevent_desc',
                         $pevent_topic,
                        '$puname',
                        '$pstartDate',
                        '$pendDate',
                         $pevent_recurrtype,
                         $pevent_recurrfreq,
                        '$pstartTime',
                        '$pendTime',
                         $pevent_allday,
                        '$pevent_category',
                        '$pevent_location',
                        '$pevent_conttel',
                        '$pevent_contname',
                        '$pevent_contemail',
                        '$pevent_website',
                        '$pevent_fee',
                         $pevent_status)";
        
        $dbconn->Execute($sql);
        if ($dbconn->ErrorNo() != 0) {
            $output->Text(_PC_EVENT_SUBMISSION_FAILED);
            $output->Linebreak(2);
        } else {
            $output->Text(_PC_EVENT_SUBMISSION_SUCCESS);
            $output->Linebreak(2);
            // clear the sql prepared vars 
            unset($pevent_subject,$pevent_desc,$pevent_topic,
                  $puname,$pstartDate,$pendDate,$pevent_recurrtype,
                  $pevent_recurrfreq,$pstartTime,$pendTime,$pevent_allday,
                  $pevent_barcolor,$pevent_location,$pevent_conttel,
                  $pevent_contname,$pevent_contemail,$pevent_website,
                  $pevent_fee,$pevent_status,$pevent_category);
            
            // clear the form vars
            $event_subject=$event_desc=$event_topic=
            $uname=$event_startday=$event_startmonth=$event_startyear=
            $event_endday=$event_endmonth=$event_endyear=$event_recurrtype=
            $event_recurrfreq=$event_starttimeh=$event_starttimem=$event_startampm=
            $event_endtimeh=$event_endtimem=$event_allday=$event_endampm=
            $event_category=$event_location=$event_conttel=
            $event_contname=$event_contemail=$event_website=
            $event_fee=$event_status=$event_category = null;
        }
        
    }
        
    // build the form
    $output->Text('<center>'._PC_SUBMISSION_FORM.'</center>');
    $output->Linebreak(2);
    $output->Text(_PC_INTRO);
    $output->Linebreak(2);
    $output->Text(_PC_DISCLAIMER);
    $output->Linebreak(2);
    
    $output->Text('<font class="pn-normal"><b>'._PC_YOURNAME.':</b> ');
    if (pnUserLoggedIn()) {
        $output->Text('<a class="pn-normal" href="user.php">' . pnUserGetVar('uname') . '</a>');
    } else {
        $output->Text(pnConfigGetVar('anonymous'));
    }
    $output->Text(' [ <a class="pn-normal" href="user.php?module=NS-User&op=logout">' . _PC_LOGOUT . '</a> ]');
    $output->Linebreak(2);
    $output->Text('<b>'._PC_EVENT_TITLE.'</b> ('._PC_BE_DESCRIPTIVE.')');
    $output->Text(' '._PC_REQUIRED);
    $output->Linebreak();
    // subject (title)
    $output->FormText('event_subject', $event_subject, 50, 80);
    $output->Linebreak();
    $output->Text('<font class="pn-normal">('._PC_BADTITLES.')</font>');
    $output->Linebreak(2);
    $output->BoldText(_PC_EVENT_DESC);
    $output->Text(' '._PC_REQUIRED);
    $output->Linebreak();
    $output->FormTextArea('event_desc', $event_desc, 6, 50);
    $output->Linebreak(2);
    
    if($displaytopics) {
        // topic select
        $output->BoldText(_PC_TOPIC.' ');
    
        $topics_table = $pntable['topics'];
        $topics_column = &$pntable['topics_column'];
        $sql = "SELECT $topics_column[topicid], $topics_column[topictext], $topics_column[topicname]
                FROM $topics_table
                ORDER BY $topics_column[topictext]";
        $topiclist = $dbconn->Execute($sql);
    
        $topic_count = 0;
        $topic_data = array();
        while(list($topicid,$topictext,$topicname) = $topiclist->fields) {
            if (pnSecAuthAction(0, 'Topics::Topic', "$topicname::$topicid", ACCESS_COMMENT)) {
	            $selected = $event_topic == $topicid ? true : false;
                $topic_data[$topic_count]['id']         = pnVarPrepForStore($topicid);
                $topic_data[$topic_count]['selected']   = $selected;
                $topic_data[$topic_count]['name']       = pnVarPrepForDisplay($topictext);
            }
            $topic_count++;
            $topiclist->MoveNext();
        }
        $output->FormSelectMultiple('event_topic', $topic_data);
        $output->Linebreak(2);
    } else {
        $output->FormHidden('event_topic','1');
    }
    
    $stimes = pnModAPIFunc('PostCalendar','user','buildTimeSelect',array('hselected'=>$event_starttimeh,'mselected'=>$event_starttimem));
    $etimes = pnModAPIFunc('PostCalendar','user','buildTimeSelect',array('hselected'=>$event_endtimeh,'mselected'=>$event_endtimem));
    
    $output->TableStart(null,null,0,null);
        $output->TableRowStart();
            $output->TableColStart(5,'left');
            $output->FormCheckbox('event_allday', $event_allday, '1');
            $output->BoldText(' '._PC_EVENT_ALLDAY);
            $output->Linebreak(2);
            $output->TableColEnd();
        $output->TableRowEnd();
        
        $output->TableRowStart();
            $output->TableColStart(1,'right');
                $output->BoldText(_PC_EVENT_BEGINS);
            $output->TableColEnd();
            $output->TableColStart(1,'left');
            // start date
            if($useinternationaldates) {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
                $output->FormSelectMultiple('event_startday', $sel_data);
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
                $output->FormSelectMultiple('event_startmonth', $sel_data);
             } else {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
                $output->FormSelectMultiple('event_startmonth', $sel_data);
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
                $output->FormSelectMultiple('event_startday', $sel_data);
            }
                $sel_data = pnModAPIFunc('PostCalendar','user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_startyear));
                $output->FormSelectMultiple('event_startyear', $sel_data);   
                
            $output->TableColEnd();
            $output->TableColStart(1,'left');
                $output->BoldText(_PC_EVENT_AT);
            $output->TableColEnd();
            $output->TableColStart();
                $output->FormSelectMultiple('event_starttimeh', $stimes['h']);
                $output->Text(' : ');
                $output->FormSelectMultiple('event_starttimem', $stimes['m']);
            $output->TableColEnd();
            
            if(!$time24hours) {
                $output->TableColStart(1,'left');
                $output->Text(' ');
                $ampm = array();
                
                $ampm[0]['id']          = pnVarPrepForStore(_AM_VAL);
                $ampm[0]['selected']    = $event_startampm == _AM_VAL;
                $ampm[0]['name']        = pnVarPrepForDisplay(_PC_AM);
                
                $ampm[1]['id']          = pnVarPrepForStore(_PM_VAL);
                $ampm[1]['selected']    = $event_startampm == _PM_VAL;
                $ampm[1]['name']        = pnVarPrepForDisplay(_PC_PM);
                $output->FormSelectMultiple('event_startampm', $ampm);
            $output->TableColEnd();
            }
            
        $output->TableRowEnd();
        
        $output->TableRowStart();
            $output->TableColStart(1,'right');
                $output->BoldText(_PC_EVENT_ENDS);
            $output->TableColEnd();
            $output->TableColStart(1,'left');
            // end date
            if($useinternationaldates) {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
                $output->FormSelectMultiple('event_endday', $sel_data);
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
                $output->FormSelectMultiple('event_endmonth', $sel_data);
            } else {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
                $output->FormSelectMultiple('event_endmonth', $sel_data);
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
                $output->FormSelectMultiple('event_endday', $sel_data);
            }
                $sel_data = pnModAPIFunc('PostCalendar','user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_endyear));
                $output->FormSelectMultiple('event_endyear', $sel_data);
            
            $output->TableColEnd();
            $output->TableColStart(1,'left');
                $output->BoldText(_PC_EVENT_AT);
            $output->TableColEnd();
            $output->TableColStart(1,'left');
                $output->FormSelectMultiple('event_endtimeh', $etimes['h']);
                $output->Text(' : ');
                $output->FormSelectMultiple('event_endtimem', $etimes['m']);
            $output->TableColEnd();
            
            if(!$time24hours) {
                $output->TableColStart(1,'left');
                $output->Text(' ');
                $ampm = array();
                $ampm[0]['id']          = pnVarPrepForStore(1);
                $ampm[0]['selected']    = $event_endampm == 1;
                $ampm[0]['name']        = pnVarPrepForDisplay(_PC_AM);
                $ampm[1]['id']          = pnVarPrepForStore(2);
                $ampm[1]['selected']    = $event_endampm == 2;
                $ampm[1]['name']        = pnVarPrepForDisplay(_PC_PM);
                $output->FormSelectMultiple('event_endampm', $ampm);
            $output->TableColEnd();
            }
        $output->TableRowEnd();
    $output->TableEnd();

    $output->TableStart(null,null,0,null);
        $output->TableRowStart();
            $output->TableColStart(5,'left');
                $output->BoldText(_PC_EVENT_CATEGORY);
            $output->TableColEnd();
        $output->TableRowEnd();
        $output->TableRowStart();
            $output->TableColStart(1,'left');
            $moddir = pnVarPrepForOS($modinfo['directory']);
            $output->TableStart();
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                
                $row[0]['content']  = $output->FormCheckbox('event_category',$event_category=='r','r','radio');
                $row[0]['align']    = 'left';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = '<img src="modules/'.$moddir.'/pnimages/ballr.gif"> '.$category1;
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                
                $row[0]['content']  = $output->FormCheckbox('event_category',$event_category=='g','g','radio');
                $row[0]['align']    = 'left';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = '<img src="modules/'.$moddir.'/pnimages/ballg.gif"> '.$category2;
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                
                $row[0]['content']  = $output->FormCheckbox('event_category',$event_category=='b','b','radio');
                $row[0]['align']    = 'left';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = '<img src="modules/'.$moddir.'/pnimages/ballb.gif"> '.$category3;
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                
                $row[0]['content']  = $output->FormCheckbox('event_category',$event_category=='w','w','radio');
                $row[0]['align']    = 'left';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = '<img src="modules/'.$moddir.'/pnimages/ballw.gif"> '.$category4;
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                
                $row[0]['content']  = $output->FormCheckbox('event_category',$event_category=='y','y','radio');
                $row[0]['align']    = 'left';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = '<img src="modules/'.$moddir.'/pnimages/bally.gif"> '.$category5;
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);  
            $output->TableEnd();
            
            $output->TableColEnd();
        $output->TableRowEnd();
    $output->TableEnd();

    $output->TableStart(null,null,0,null);
          
        $output->TableRowStart();
            $output->TableColStart(1,'left');
            $output->BoldText(_PC_EVENT_RECURRTYPE);
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrtype', $event_recurrtype<0, '-1', 'radio');
            $output->Text(_PC_EVENT_RECURRTYPE_NONE);
            
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrtype', $event_recurrtype==0, '0', 'radio');
            $output->Text(_PC_EVENT_RECURRTYPE_DAILY);
            
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrtype', $event_recurrtype==1, '1', 'radio');
            $output->Text(_PC_EVENT_RECURRTYPE_WEEKLY);
                        
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrtype', $event_recurrtype==2, '2', 'radio');
            $output->Text(_PC_EVENT_RECURRTYPE_MONTHLY);
            
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrtype', $event_recurrtype==3, '3', 'radio');
            $output->Text(_PC_EVENT_RECURRTYPE_YEARLY);
            
            $output->Linebreak(2);
            $output->TableColEnd();
        $output->TableRowEnd();
        
        $output->TableRowStart();
            $output->TableColStart(1,'left');
            $output->BoldText(_PC_EVENT_RECURRFREQ);
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrfreq', $event_recurrfreq==0, '0', 'radio');
            $output->Text(_PC_EVENT_RECURRFREQ_DAY);
            
            $output->Linebreak();
            
            $output->FormCheckbox('event_recurrfreq', $event_recurrfreq==1, '1', 'radio');
            $output->Text(_PC_EVENT_RECURRFREQ_DATE);
            
            $output->Linebreak(2);
            $output->TableColEnd();
        $output->TableRowEnd();
    $output->TableEnd();
    
    $output->TableStart(null,null,0,null);
        $output->TableRowStart();
            $output->TableColStart(1,'left');
            
            $output->TableStart();
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_LOCATION.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_location',$event_location,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_CONTNAME.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_contname',$event_contname,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_CONTTEL.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_conttel',$event_conttel,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_CONTEMAIL.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_contemail',$event_contemail,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_WEBSITE.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_website',$event_website,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);  
                
                $output->SetOutputMode(_PNH_RETURNOUTPUT);
                $row[0]['content']  = _PC_EVENT_FEE.' : ';
                $row[0]['align']    = 'right';
                $row[0]['valign']   = 'middle';
                $row[1]['content']  = $output->FormText('event_fee',$event_fee,50,80);
                $row[1]['align']    = 'left';
                $row[1]['valign']   = 'middle';
                $output->SetOutputMode(_PNH_KEEPOUTPUT);
                $output->TableAddRow($row);  
            $output->TableEnd();
            
            $output->TableColEnd();
        $output->TableRowEnd();
    $output->TableEnd();
    
    $output->Text('<input type="submit" tabindex="'.$output->tabindex++.'" name="preview" value="'._PC_EVENT_PREVIEW.'">');
    if($preview) {
        $output->Text('<input type="submit" tabindex="'.$output->tabindex++.'" name="commit" value="'._PC_EVENT_SUBMIT.'">');
    }
    $output->FormEnd();
    
    return $output->GetOutput();
}

/**
 * search events
 */
function PostCalendar_user_search()
{   
    // let's load the User API so we can use it
    if(!pnModAPILoad('PostCalendar','user')) {
        die('Could not load PostCalendar user API');
    }
    
    $output = new pnHTML();
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    
    // load the DHTML JavaScript code and insert it into the page
    if (pnModGetVar('PostCalendar','usepopups')) {
        $output->Text(pnModAPIFunc('PostCalendar','user','loadPopups'));
    }

    // insert the js popup code into the page
    if(pnModGetVar('PostCalendar','eventsopeninnewwindow')) {
        $output->Text(pnModAPIFunc('PostCalendar','user','jsPopup'));
    }

    
    $output->Text(PostCalendar_usermenu(array('Date'=>Date('d/m/Y'))));
    $output->FormStart(pnModUrl('PostCalendar','user','search'));
    $output->TableStart(_PC_SEARCH_FORM);
    $output->Text(_PC_SEARCH_KEYWORDS.' ');
    $output->FormText('keywords',null, 50);
    $output->Linebreak(2);
    $output->FormSubmit(_PC_SEARCH_PERFORM);
    $output->TableEnd();
    $output->FormEnd();
    
    $keywords = pnVarCleanFromInput('keywords');
    if(!empty($keywords)) {
        pnModDBInfoLoad('PostCalendar');
        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();
    
        // link to the events tables
        $events_table = $pntable['postcalendar_events'];
        $events_column = &$pntable['postcalendar_events_column'];
        
        // perform the search
        $sql =  "SELECT $events_column[eid], 
                        $events_column[title], 
                        $events_column[hometext], 
                        $events_column[eventDate], 
                        $events_column[endDate], 
                        $events_column[startTime], 
                        $events_column[endTime], 
                        $events_column[barcolor], 
                        $events_column[recurrtype], 
                        $events_column[recurrfreq],
                        $events_column[alldayevent],
                        $events_column[topic] 
             
                 FROM   $events_table
             
                 WHERE  $events_column[eventstatus] = 1
                        AND (    $events_column[title] LIKE '%$keywords%'
                              OR $events_column[hometext] LIKE '%$keywords%')
             
                 ORDER BY $events_column[eventDate],$events_column[startTime] ASC
                 LIMIT 50"; 
                 
        $result = $dbconn->Execute($sql);
    
         // put the information into an array for easy access
        if($result->NumRows() > 0) {
            $output->Linebreak(2);
            $output->BoldText(_PC_SEARCH_RESULTS);
            $output->Linebreak();
        }
        $events = array();
    
        for($e=0; !$result->EOF; $result->MoveNext()) {
            list($eid,$title,$hometext,$eventDate,$endDate,$startTime,$endTime,
                 $barcolor,$recurrtype,$recurrfreq,$alldayevent,$topic) = $result->fields;
             
            $events['eid']          = $eid;
            $events['title']        = $title;
            $events['hometext']     = $hometext;
            $events['eventDate']    = $eventDate;
            $events['endDate']      = $endDate;
            $events['startTime']    = $startTime;
            $events['endTime']      = $endTime;
            $events['barcolor']     = $barcolor;
            $events['recurrtype']   = $recurrtype;
            $events['recurrfreq']   = $recurrfreq;
            $events['alldayevent']  = $alldayevent;
            $events['topic']        = $topic;
            $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
                                        array('event'=>$events,'search'=>1)));
            $e++;
        }
        if($result->NumRows() >= 50) {
            $output->Linebreak(2);
            $output->BoldText(_PC_SEARCH_MAX);
            $output->Linebreak();
        }
    }
    
    return $output->GetOutput();
}

/**
 * generate menu fragment
 */
function PostCalendar_usermenu($args)
{
    pnThemeLoad(pnUserGetTheme());
    // get the theme globals :: is there a better way to do this?
    global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
    global $textcolor1, $textcolor2;
    
    // set some globals for easier code readability
    define('_EVENT_APPROVED',   1);
    define('_EVENT_QUEUED',     0);
    if(!defined('_AM_VAL')) define('_AM_VAL', 1);
    if(!defined('_PM_VAL')) define('_PM_VAL', 2);
    
    extract($args);
    if(!isset($Date)) {
        //$Date = date('m/d/Y');
        $time = time();
        $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
        $Date = ml_ftime('%m/%d/%Y',$time);
    }
    list($month,$day,$year) = explode('/',$Date);
    
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();
    $output->SetInputMode(_PNH_VERBATIMINPUT);
        
    // lets get the module's information
    $modid      = pnModGetIDFromName('PostCalendar');
    $modinfo    = pnModGetInfo($modid);
    
    if (!pnModAPILoad('PostCalendar', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }
    
    $output->Text(pnGetStatusMsg());
    //$output->Linebreak();

    // here we build the contents of the main menu
    // create the urls to use
    $create_event_url = pnModURL('PostCalendar','user','submit');
    $day_view_url     = pnModUrl('PostCalendar','user','view',array('viewtype'=>'day','Date'=>$Date));
    $week_view_url    = pnModUrl('PostCalendar','user','view',array('viewtype'=>'week','Date'=>$Date));
    $month_view_url   = pnModUrl('PostCalendar','user','view',array('viewtype'=>'month','Date'=>$Date));
    $year_view_url    = pnModUrl('PostCalendar','user','view',array('viewtype'=>'year','Date'=>$Date));
    $submit_event_url = pnModURL('PostCalendar','user','submit');
    $search_event_url = pnModURL('PostCalendar','user','search');
    // all done
    $output->FormStart(pnModUrl('PostCalendar','user','view'));
    $output->tabindex=1000;
    $output->Text('<table border="0" cellpadding="1" cellspacing="0" width="100%" bgcolor="'.$bgcolor2.'"><tr><td>');
    $output->Text('<table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="'.$bgcolor1.'">');
        $output->Text('<tr>');
            $output->Text('<td width="10" align="left" valign="top">');
            $output->Text('<center><img src="modules/'.$modinfo['directory'].'/pnimages/admin.gif"></center>');
            $output->Text('</td>');
            
            $output->Text('<td align="center" valign="top">');
            $output->Text('<font class="pn-logo">'._POSTCALENDAR.'</font>');
            $output->Linebreak(2);
            
            $output->Text('[ ');
            $output->URL($day_view_url,_CALDAYLINK);
            $output->Text(' ]');
            $output->Text(' [ ');
            $output->URL($week_view_url,_CALWEEKLINK);
            $output->Text(' ]');
            $output->Text(' [ ');
            $output->URL($month_view_url,_CALMONTHLINK);
            $output->Text(' ]');
            $output->Text(' [ ');
            $output->URL($year_view_url,_CALYEARLINK);
            $output->Text(' ]');
            $output->Text(' [ ');
            $output->URL($submit_event_url,_CALSUBMITEVENT);
            $output->Text(' ]');
            $output->Text(' [ ');
            $output->URL($search_event_url,_CALSEARCHEVENT);
            $output->Text(' ]');
            
            $output->Linebreak(2);
            $output->Text(_CALJUMPTOTEXT);
            if(pnModGetVar('PostCalendar','useinternationaldates')) {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day));
                $output->FormSelectMultiple('jumpday', $sel_data);
                
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month));
                $output->FormSelectMultiple('jumpmonth', $sel_data);
                
                $sel_data = pnModAPIFunc('PostCalendar','user','buildYearSelect',array('pc_year'=>$year));
                $output->FormSelectMultiple('jumpyear', $sel_data);
            } else {
                $sel_data = pnModAPIFunc('PostCalendar','user','buildMonthSelect',array('pc_month'=>$month));
                $output->FormSelectMultiple('jumpmonth', $sel_data);
                
                $sel_data = pnModAPIFunc('PostCalendar','user','buildDaySelect',array('pc_day'=>$day));
                $output->FormSelectMultiple('jumpday', $sel_data);
                
                $sel_data = pnModAPIFunc('PostCalendar','user','buildYearSelect',array('pc_year'=>$year));
                $output->FormSelectMultiple('jumpyear', $sel_data);
            }
            $sel_data = array();
            $sel_data[0]['id']         = 'day';
            $sel_data[0]['selected']   = 0;
            $sel_data[0]['name']       = _CAL_DAYVIEW;
            $sel_data[1]['id']         = 'week';
            $sel_data[1]['selected']   = 0;
            $sel_data[1]['name']       = _CAL_WEEKVIEW;
            $sel_data[2]['id']         = 'month';
            $sel_data[2]['selected']   = 0;
            $sel_data[2]['name']       = _CAL_MONTHVIEW;
            $sel_data[3]['id']         = 'year';
            $sel_data[3]['selected']   = 0;
            $sel_data[3]['name']       = _CAL_YEARVIEW;
            $output->FormSelectMultiple('viewtype', $sel_data);
            $output->FormSubmit(_CALJUMPTEXT);
            $output->Linebreak();
            $output->Text('</td>');
            
            $output->Text('<td width="10" align="left" valign="top">');
            $output->Text(_PC_LEGEND);
            $output->Linebreak();
            $output->Text('<img src="modules/'.$modinfo['directory'].'/pnimages/ballr.gif">&nbsp;&nbsp;');
            $output->Text(pnModGetVar('PostCalendar','category1').'&nbsp;&nbsp;');
            $output->Linebreak();
            $output->Text('<img src="modules/'.$modinfo['directory'].'/pnimages/ballg.gif">&nbsp;&nbsp;');
            $output->Text(pnModGetVar('PostCalendar','category2').'&nbsp;&nbsp;');
            $output->Linebreak();
            $output->Text('<img src="modules/'.$modinfo['directory'].'/pnimages/ballb.gif">&nbsp;&nbsp;');
            $output->Text(pnModGetVar('PostCalendar','category3').'&nbsp;&nbsp;');
            $output->Linebreak();
            $output->Text('<img src="modules/'.$modinfo['directory'].'/pnimages/ballw.gif">&nbsp;&nbsp;');
            $output->Text(pnModGetVar('PostCalendar','category4').'&nbsp;&nbsp;');
            $output->Linebreak();
            $output->Text('<img src="modules/'.$modinfo['directory'].'/pnimages/bally.gif">&nbsp;&nbsp;');
            $output->Text(pnModGetVar('PostCalendar','category5').'&nbsp;&nbsp;');
            $output->Text('</td>');
        $output->Text('</tr>');
    $output->Text('</table>');    
    $output->Text('</td></tr></table>');
    $output->FormEnd();
    $output->Linebreak();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

function PostCalendar_footer()
{   
    // lets get the module's information
    $modinfo = pnModGetInfo(pnModGetIDFromName('PostCalendar'));
    
    $footer = "<p align=\"center\"><a href=\"http://www.bosrup.com/web/overlib/\" 
                  target=\"_blank\"><img 
                  src=\"modules/$modinfo[directory]/pnimages/overlib.gif\" 
                  width=\"88\" 
                  height=\"31\" 
                  alt=\"Popups by overLIB!\" 
                  border=\"0\"></a></p>";
        
    return $footer;
}
?>
Return current item: Nuke Modules CVS