[ Index ]

krapohl.info

title

Body

[close]

/ -> pnadmin.php (source)

   1  <?php
   2  @define('__POSTCALENDAR__','PostCalendar');
   3  /** 
   4   *  $Id: pnadmin.php,v 1.1 2004/02/11 17:25:28 larsneo Exp $
   5   *
   6   *  PostCalendar::PostNuke Events Calendar Module
   7   *  Copyright (C) 2002  The PostCalendar Team
   8   *  http://postcalendar.tv
   9   *  
  10   *  This program is free software; you can redistribute it and/or modify
  11   *  it under the terms of the GNU General Public License as published by
  12   *  the Free Software Foundation; either version 2 of the License, or
  13   *  (at your option) any later version.
  14   *  
  15   *  This program is distributed in the hope that it will be useful,
  16   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18   *  GNU General Public License for more details.
  19   *  
  20   *  You should have received a copy of the GNU General Public License
  21   *  along with this program; if not, write to the Free Software
  22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23   *
  24   *  To read the license please read the docs/license.txt or visit
  25   *  http://www.gnu.org/copyleft/gpl.html
  26   *
  27   */
  28  //=========================================================================
  29  //  Load the API Functions
  30  //=========================================================================
  31  pnModAPILoad(__POSTCALENDAR__,'admin');
  32  
  33  /**
  34   * the main administration function
  35   * This function is the default function, and is called whenever the
  36   * module is initiated without defining arguments.  As such it can
  37   * be used for a number of things, but most commonly it either just
  38   * shows the module menu and returns or calls whatever the module
  39   * designer feels should be the default function (often this is the
  40   * view() function)
  41   */
  42  function postcalendar_admin_main()
  43  {
  44      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
  45      return postcalendar_admin_modifyconfig();
  46  }
  47  function postcalendar_admin_listapproved() { return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN); }
  48  function postcalendar_admin_listhidden() { return postcalendar_admin_showlist('',_EVENT_HIDDEN,'listhidden',_PC_HIDDEN_ADMIN); }
  49  function postcalendar_admin_listqueued() { return postcalendar_admin_showlist('',_EVENT_QUEUED,'listqueued',_PC_QUEUED_ADMIN); }
  50  function postcalendar_admin_showlist($e='',$type,$function,$title,$msg='')
  51  {
  52      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
  53      
  54      $output = postcalendar_adminmenu();
  55      
  56      if(!empty($e)) { 
  57          $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
  58          $output .= '<center><b>'.$e.'</b></center>';
  59          $output .= '</div><br />';
  60      }
  61      
  62      if(!empty($msg)) { 
  63          $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
  64          $output .= '<center><b>'.$msg.'</b></center>';
  65          $output .= '</div><br />';
  66      }
  67      
  68      $offset_increment = _SETTING_HOW_MANY_EVENTS;
  69      if(empty($offset_increment)) $offset_increment = 15;
  70      
  71      pnThemeLoad(pnUserGetTheme());
  72      // get the theme globals :: is there a better way to do this?
  73      global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
  74      global $textcolor1, $textcolor2;
  75      
  76      $offset = pnVarCleanFromInput('offset');
  77      $sort = pnVarCleanFromInput('sort');
  78      $sdir = pnVarCleanFromInput('sdir');
  79      if(!isset($sort)) $sort = 'time';
  80      if(!isset($sdir)) $sdir = 1;
  81      if(!isset($offset))  $offset = 0;
  82      
  83      $result = pnModAPIFunc(__POSTCALENDAR__,'admin','getAdminListEvents',
  84                             array('type'=>$type,
  85                                   'sdir'=>$sdir,
  86                                   'sort'=>$sort,
  87                                   'offset'=>$offset,
  88                                   'offset_increment'=>$offset_increment));
  89      
  90      $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','buildAdminList',
  91                                array('type'=>$type,
  92                                        'title'=>$title,
  93                                       'sdir'=>$sdir,
  94                                       'sort'=>$sort,
  95                                       'offset'=>$offset,
  96                                       'offset_increment'=>$offset_increment,
  97                                       'function'=>$function,
  98                                       'result'=>$result));
  99      
 100      
 101      return $output;
 102  }
 103  
 104  function postcalendar_admin_adminevents()
 105  {
 106      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 107      
 108      $output = '';
 109      list($action,$pc_event_id,$thelist) = pnVarCleanFromInput('action','pc_event_id','thelist');
 110      
 111      if(!isset($pc_event_id)) {
 112          $e  = _PC_NO_EVENT_SELECTED;
 113          
 114          switch($thelist) {
 115              case 'listqueued' :
 116                  $output .= postcalendar_admin_showlist($e,_EVENT_QUEUED,'showlist');
 117                  break;
 118                  
 119              case 'listhidden' :
 120                  $output .= postcalendar_admin_showlist($e,_EVENT_HIDDEN,'showlist');
 121                  break;
 122                  
 123              case 'listapproved' :
 124                  $output .= postcalendar_admin_showlist($e,_EVENT_APPROVED,'showlist');
 125                  break;
 126          }
 127          return $output;     
 128      }
 129      
 130      // main menu
 131      $output = postcalendar_adminmenu();
 132      $function = '';
 133      switch ($action) {
 134          case _ADMIN_ACTION_APPROVE :
 135              $function = 'approveevents';
 136              $are_you_sure_text = _PC_APPROVE_ARE_YOU_SURE;
 137              break;
 138              
 139          case _ADMIN_ACTION_HIDE :
 140              $function = 'hideevents';
 141              $are_you_sure_text = _PC_HIDE_ARE_YOU_SURE;
 142              break;
 143              
 144          case _ADMIN_ACTION_DELETE :
 145              $function = 'deleteevents';
 146              $are_you_sure_text = _PC_DELETE_ARE_YOU_SURE;
 147              break;
 148      }
 149      
 150      if(!empty($function)) {
 151          $output .= '<form action="'.pnModUrl(__POSTCALENDAR__,'admin',$function).'" method="post">';
 152          $output .= $are_you_sure_text.' ';
 153          $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
 154          $output .= '<br /><br />';
 155      }
 156      if(is_array($pc_event_id)) {
 157          foreach($pc_event_id as $eid) {
 158              $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','eventDetail',array('eid'=>$eid,'nopop'=>true));
 159              $output .= '<br /><br />';
 160              $output .= '<input type="hidden" name="pc_eid[]" value="'.$eid.'" />';
 161          }
 162      } else {
 163          $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','eventDetail',array('eid'=>$pc_event_id,'nopop'=>true));
 164          $output .= '<br /><br />';
 165          $output .= '<input type="hidden" name="pc_eid[]" value="'.$pc_event_id.'" />';
 166      }
 167      if(!empty($function)) {
 168          $output .= $are_you_sure_text.' ';
 169          $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
 170          $output .= '</form>';
 171      }
 172      
 173      return $output;
 174  }
 175  
 176  function postcalendar_admin_approveevents()
 177  {
 178      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 179      
 180      $pc_eid = pnVarCleanFromInput('pc_eid');
 181      $approve_list = '';
 182      foreach($pc_eid as $eid) {
 183          if(!empty($approve_list)) { $approve_list .= ','; }
 184          $approve_list .= $eid;
 185      }
 186      
 187      list($dbconn) = pnDBGetConn();
 188      $pntable = pnDBGetTables();
 189      $events_table = $pntable['postcalendar_events'];
 190      $events_column = &$pntable['postcalendar_events_column'];
 191      
 192      $sql = "UPDATE $events_table
 193              SET $events_column[eventstatus] = "._EVENT_APPROVED."
 194              WHERE $events_column[eid] IN ($approve_list)";
 195  
 196      $dbconn->Execute($sql);
 197      if ($dbconn->ErrorNo() != 0) { 
 198          $msg = _PC_ADMIN_EVENT_ERROR; 
 199      } else { 
 200          $msg = _PC_ADMIN_EVENTS_APPROVED; 
 201      }
 202      
 203      // clear the template cache
 204      $tpl =& new pcSmarty();
 205      $tpl->clear_all_cache();
 206      return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
 207  }
 208  
 209  function postcalendar_admin_hideevents()
 210  {
 211      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 212      
 213      $pc_eid = pnVarCleanFromInput('pc_eid');
 214      $output = postcalendar_adminmenu();
 215      $event_list = '';
 216      foreach($pc_eid as $eid) {
 217          if(!empty($event_list)) { $event_list .= ','; }
 218          $event_list .= $eid;
 219      }
 220      
 221      list($dbconn) = pnDBGetConn();
 222      $pntable = pnDBGetTables();
 223      $events_table = $pntable['postcalendar_events'];
 224      $events_column = &$pntable['postcalendar_events_column'];
 225      
 226      $sql = "UPDATE $events_table
 227              SET $events_column[eventstatus] = "._EVENT_HIDDEN."
 228              WHERE $events_column[eid] IN ($event_list)";
 229  
 230      $dbconn->Execute($sql);
 231      if ($dbconn->ErrorNo() != 0) {
 232          $msg = _PC_ADMIN_EVENT_ERROR;
 233      } else {
 234          $msg = _PC_ADMIN_EVENTS_HIDDEN;
 235      }
 236      
 237      // clear the template cache
 238      $tpl =& new pcSmarty();
 239      $tpl->clear_all_cache();
 240      return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
 241  }
 242  
 243  function postcalendar_admin_deleteevents()
 244  {
 245      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 246      
 247      $pc_eid = pnVarCleanFromInput('pc_eid');
 248      $output = postcalendar_adminmenu();
 249      $event_list = '';
 250      foreach($pc_eid as $eid) {
 251          if(!empty($event_list)) { $event_list .= ','; }
 252          $event_list .= $eid;
 253      }
 254      
 255      list($dbconn) = pnDBGetConn();
 256      $pntable = pnDBGetTables();
 257      $events_table = $pntable['postcalendar_events'];
 258      $events_column = &$pntable['postcalendar_events_column'];
 259      
 260      $sql = "DELETE FROM $events_table WHERE $events_column[eid] IN ($event_list)";
 261  
 262      $dbconn->Execute($sql);
 263      if ($dbconn->ErrorNo() != 0) {
 264          $msg = _PC_ADMIN_EVENT_ERROR;
 265      } else {
 266          $msg = _PC_ADMIN_EVENTS_DELETED;
 267      }
 268      
 269      // clear the template cache
 270      $tpl =& new pcSmarty();
 271      $tpl->clear_all_cache();
 272      return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
 273  }
 274  
 275  function postcalendar_admin_edit($args) { return postcalendar_admin_submit($args); }
 276  function postcalendar_admin_submit($args)
 277  {   
 278      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 279      
 280      pnModAPILoad(__POSTCALENDAR__,'user');
 281      $output = postcalendar_adminmenu();
 282      
 283      // get the theme globals :: is there a better way to do this?
 284      pnThemeLoad(pnUserGetTheme());
 285      global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $textcolor1, $textcolor2;
 286      
 287      extract($args);
 288      
 289      $Date = postcalendar_getDate();
 290      $year   = substr($Date,0,4);
 291      $month  = substr($Date,4,2);
 292      $day    = substr($Date,6,2);
 293      
 294      // basic event information
 295      $event_subject      = pnVarCleanFromInput('event_subject');
 296      $event_desc         = pnVarCleanFromInput('event_desc');
 297      $event_sharing      = pnVarCleanFromInput('event_sharing');
 298      $event_category     = pnVarCleanFromInput('event_category');
 299      $event_topic         = pnVarCleanFromInput('event_topic');
 300      
 301      // event start information
 302      $event_startmonth     = pnVarCleanFromInput('event_startmonth');
 303      $event_startday     = pnVarCleanFromInput('event_startday');
 304      $event_startyear     = pnVarCleanFromInput('event_startyear');
 305      $event_starttimeh    = pnVarCleanFromInput('event_starttimeh');
 306      $event_starttimem     = pnVarCleanFromInput('event_starttimem');
 307      $event_startampm     = pnVarCleanFromInput('event_startampm');
 308      
 309      // event end information
 310      $event_endmonth     = pnVarCleanFromInput('event_endmonth');
 311      $event_endday         = pnVarCleanFromInput('event_endday');
 312      $event_endyear      = pnVarCleanFromInput('event_endyear');
 313      $event_endtype      = pnVarCleanFromInput('event_endtype');
 314      $event_dur_hours     = pnVarCleanFromInput('event_dur_hours');
 315      $event_dur_minutes  = pnVarCleanFromInput('event_dur_minutes');
 316      $event_duration     = (60*60*$event_dur_hours) + (60*$event_dur_minutes);
 317      $event_allday         = pnVarCleanFromInput('event_allday');
 318      
 319      // location data
 320      $event_location     = pnVarCleanFromInput('event_location');
 321      $event_street1      = pnVarCleanFromInput('event_street1');
 322      $event_street2      = pnVarCleanFromInput('event_street2');
 323      $event_city         = pnVarCleanFromInput('event_city');
 324      $event_state         = pnVarCleanFromInput('event_state');
 325      $event_postal         = pnVarCleanFromInput('event_postal');
 326      $event_location_info = serialize(compact('event_location', 'event_street1', 'event_street2',
 327                                               'event_city', 'event_state', 'event_postal'));
 328      // contact data
 329      $event_contname     = pnVarCleanFromInput('event_contname');
 330      $event_conttel      = pnVarCleanFromInput('event_conttel');
 331      $event_contemail     = pnVarCleanFromInput('event_contemail');
 332      $event_website      = pnVarCleanFromInput('event_website');
 333      $event_fee          = pnVarCleanFromInput('event_fee');
 334      
 335      // event repeating data
 336      $event_repeat         = pnVarCleanFromInput('event_repeat');
 337      $event_repeat_freq  = pnVarCleanFromInput('event_repeat_freq');
 338      $event_repeat_freq_type = pnVarCleanFromInput('event_repeat_freq_type');
 339      $event_repeat_on_num = pnVarCleanFromInput('event_repeat_on_num');
 340      $event_repeat_on_day = pnVarCleanFromInput('event_repeat_on_day');
 341      $event_repeat_on_freq = pnVarCleanFromInput('event_repeat_on_freq');
 342      $event_recurrspec = serialize(compact('event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num',
 343                                            'event_repeat_on_day', 'event_repeat_on_freq'));
 344      
 345      $pc_html_or_text = pnVarCleanFromInput('pc_html_or_text');
 346      $form_action = pnVarCleanFromInput('form_action');
 347      $pc_event_id = pnVarCleanFromInput('pc_event_id');
 348      $data_loaded = pnVarCleanFromInput('data_loaded');
 349      $is_update   = pnVarCleanFromInput('is_update');
 350      $authid      = pnVarCleanFromInput('authid');
 351      
 352      if(pnUserLoggedIn()) { $uname = pnUserGetVar('uname'); } 
 353      else { $uname = pnConfigGetVar('anonymous'); }
 354      if(!isset($event_repeat)) { $event_repeat = 0; }
 355      
 356      // lets wrap all the data into array for passing to submit and preview functions
 357      if(!isset($pc_event_id) || empty($pc_event_id) || $data_loaded) {
 358          $eventdata = compact('event_subject','event_desc','event_sharing','event_category','event_topic',
 359          'event_startmonth','event_startday','event_startyear','event_starttimeh','event_starttimem','event_startampm',
 360          'event_endmonth','event_endday','event_endyear','event_endtype','event_dur_hours','event_dur_minutes',
 361          'event_duration','event_allday','event_location','event_street1','event_street2','event_city','event_state',
 362          'event_postal','event_location_info','event_contname','event_conttel','event_contemail',
 363          'event_website','event_fee','event_repeat','event_repeat_freq','event_repeat_freq_type',
 364          'event_repeat_on_num','event_repeat_on_day','event_repeat_on_freq','event_recurrspec','uname',
 365          'Date','year','month','day','pc_html_or_text');
 366          $eventdata['is_update'] = $is_update;
 367          $eventdata['pc_event_id'] = $pc_event_id;
 368          $eventdata['data_loaded'] = true;
 369      } else {
 370          $event = postcalendar_userapi_pcGetEventDetails($pc_event_id);
 371          $eventdata['event_subject'] = $event['title'];
 372          $eventdata['event_desc'] = $event['hometext'];
 373          $eventdata['event_sharing'] = $event['sharing'];
 374          $eventdata['event_category'] = $event['catid'];
 375          $eventdata['event_topic'] = $event['topic'];
 376          $eventdata['event_startmonth'] = substr($event['eventDate'],5,2);
 377          $eventdata['event_startday'] = substr($event['eventDate'],8,2);
 378          $eventdata['event_startyear'] = substr($event['eventDate'],0,4);
 379          $eventdata['event_starttimeh'] = substr($event['startTime'],0,2);
 380          $eventdata['event_starttimem'] = substr($event['startTime'],3,2);
 381          $eventdata['event_startampm'] = $eventdata['event_starttimeh'] < 12 ? _PC_AM : _PC_PM ;
 382          $eventdata['event_endmonth'] = substr($event['endDate'],5,2);
 383          $eventdata['event_endday'] = substr($event['endDate'],8,2);
 384          $eventdata['event_endyear'] = substr($event['endDate'],0,4);
 385          $eventdata['event_endtype'] = $event['endDate'] == '0000-00-00' ? '0' : '1' ;
 386          $eventdata['event_dur_hours'] = $event['duration_hours'];
 387          $eventdata['event_dur_minutes'] = $event['duration_minutes'];
 388          $eventdata['event_duration'] = $event['duration'];
 389          $eventdata['event_allday'] = $event['alldayevent'];
 390          $loc_data = unserialize($event['location']);
 391          $eventdata['event_location'] = $loc_data['event_location'];
 392          $eventdata['event_street1'] = $loc_data['event_street1'];
 393          $eventdata['event_street2'] = $loc_data['event_street2'];
 394          $eventdata['event_city'] = $loc_data['event_city'];
 395          $eventdata['event_state'] = $loc_data['event_state'];
 396          $eventdata['event_postal'] = $loc_data['event_postal'];
 397          $eventdata['event_location_info'] = $loc_data;
 398          $eventdata['event_contname'] = $event['contname'];
 399          $eventdata['event_conttel'] = $event['conttel'];
 400          $eventdata['event_contemail'] = $event['contemail'];
 401          $eventdata['event_website'] = $event['website'];
 402          $eventdata['event_fee'] = $event['fee'];
 403          $eventdata['event_repeat'] = $event['recurrtype'];
 404          $rspecs = unserialize($event['recurrspec']);
 405          $eventdata['event_repeat_freq'] = $rspecs['event_repeat_freq'];
 406          $eventdata['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
 407          $eventdata['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
 408          $eventdata['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
 409          $eventdata['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
 410          $eventdata['event_recurrspec'] = $rspecs;
 411          $eventdata['uname'] = $uname;
 412          $eventdata['Date'] = $Date;
 413          $eventdata['year'] = $year;
 414          $eventdata['month'] = $month;
 415          $eventdata['day'] = $day;
 416          $eventdata['is_update'] = true;
 417          $eventdata['pc_event_id'] = $pc_event_id;
 418          $eventdata['data_loaded'] = true;
 419          $eventdata['pc_html_or_text'] = $pc_html_or_text;
 420      }
 421      
 422      // lets get the module's information
 423      $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
 424      $categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
 425      
 426      //================================================================
 427      //    ERROR CHECKING
 428      //================================================================
 429      $required_vars = array('event_subject','event_desc');
 430      $required_name = array(_PC_EVENT_TITLE,_PC_EVENT_DESC);
 431      $error_msg = '';
 432      $reqCount = count($required_vars);
 433      for ($r=0; $r<$reqCount; $r++) {
 434          if(empty($$required_vars[$r]) || !preg_match('/\S/i',$$required_vars[$r])) {
 435              $error_msg .= '<b>' . $required_name[$r] . '</b> ' . _PC_SUBMIT_ERROR4 . '<br />';
 436          }
 437      }
 438      unset($reqCount);
 439      // check repeating frequencies
 440      if($event_repeat == REPEAT) {
 441          if(!isset($event_repeat_freq) ||  $event_repeat_freq < 1 || empty($event_repeat_freq)) {
 442              $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
 443          } elseif(!is_numeric($event_repeat_freq)) {
 444              $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
 445          }
 446      } elseif($event_repeat == REPEAT_ON) {
 447          if(!isset($event_repeat_on_freq) || $event_repeat_on_freq < 1 || empty($event_repeat_on_freq)) {
 448              $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
 449          } elseif(!is_numeric($event_repeat_on_freq)) {
 450              $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
 451          }
 452      }
 453      // check date validity
 454      if(_SETTING_TIME_24HOUR) {
 455          $startTime = $event_starttimeh.':'.$event_starttimem;
 456          $endTime =   $event_endtimeh.':'.$event_endtimem;
 457      } else {
 458          if($event_startampm == _AM_VAL) {
 459              $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
 460          } else {
 461              $event_starttimeh =  $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
 462          }
 463          $startTime = $event_starttimeh.':'.$event_starttimem;
 464      }
 465      $sdate = strtotime($event_startyear.'-'.$event_startmonth.'-'.$event_startday);
 466      $edate = strtotime($event_endyear.'-'.$event_endmonth.'-'.$event_endday);
 467      $tdate = strtotime(date('Y-m-d'));
 468      if($edate < $sdate && $event_endtype == 1) {
 469          $error_msg .= _PC_SUBMIT_ERROR1 . '<br />';
 470      }
 471      if(!checkdate($event_startmonth,$event_startday,$event_startyear)) {
 472          $error_msg .= _PC_SUBMIT_ERROR2 . '<br />';
 473      }
 474      if(!checkdate($event_endmonth,$event_endday,$event_endyear)) {
 475          $error_msg .= _PC_SUBMIT_ERROR3 . '<br />';
 476      }
 477      
 478      //================================================================
 479      //    Preview the event
 480      //================================================================
 481      if($form_action == 'preview') {
 482          if(!empty($error_msg)) {
 483              $preview = false;
 484              $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
 485              $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
 486                  $output .= '<center><b>' . _PC_SUBMIT_ERROR . '</b></center>'; 
 487                  $output .= '<br />';
 488                  $output .= $error_msg;
 489              $output .= '</td></td></table>';
 490              $output .= '</td></td></table>';
 491              $output .= '<br /><br />';
 492          } else {
 493              $output .= pnModAPIFunc(__POSTCALENDAR__,'user','eventPreview',$eventdata);
 494              $output .= '<br />';
 495          }
 496      }
 497      
 498      //================================================================
 499      //    Enter the event into the DB
 500      //================================================================
 501      if($form_action == 'commit') {
 502          //if (!pnSecConfirmAuthKey()) { return(_NO_DIRECT_ACCESS); }
 503          if(!empty($error_msg)) {
 504              $preview = false;
 505              $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
 506              $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
 507                  $output .= '<center><b>'._PC_SUBMIT_ERROR.'</b></center>'; 
 508                  $output .= '<br />';
 509                  $output .= $error_msg;
 510              $output .= '</td></td></table>';
 511              $output .= '</td></td></table>';
 512              $output .= '<br /><br />';
 513          } else {
 514              if (!pnModAPIFunc(__POSTCALENDAR__,'admin','submitEvent',$eventdata)) {
 515                  $output .= '<center><div style="padding:5px; border:1px solid red; background-color: pink;">';        
 516                  $output .= "<b>"._PC_EVENT_SUBMISSION_FAILED."</b>";        
 517                  $output .= '</div></center><br />';    
 518                  $output .= '<br />';
 519              } else {
 520                  // clear the Smarty cache
 521                  $tpl =& new pcSmarty();
 522                  $tpl->clear_all_cache();
 523                  $output .= '<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">';        
 524                  if($is_update) {
 525                      $output .= "<b>"._PC_EVENT_EDIT_SUCCESS."</b>";        
 526                  } else {
 527                      $output .= "<b>"._PC_EVENT_SUBMISSION_SUCCESS."</b>";        
 528                  }
 529                  $output .= '</div></center><br />';    
 530                  $output .= '<br />';
 531                  // clear the form vars
 532                  $event_subject=$event_desc=$event_sharing=$event_category=$event_topic=
 533                  $event_startmonth=$event_startday=$event_startyear=$event_starttimeh=$event_starttimem=$event_startampm=
 534                  $event_endmonth=$event_endday=$event_endyear=$event_endtype=$event_dur_hours=$event_dur_minutes=
 535                  $event_duration=$event_allday=$event_location=$event_street1=$event_street2=$event_city=$event_state=
 536                  $event_postal=$event_location_info=$event_contname=$event_conttel=$event_contemail=
 537                  $event_website=$event_fee=$event_repeat=$event_repeat_freq=$event_repeat_freq_type=
 538                  $event_repeat_on_num=$event_repeat_on_day=$event_repeat_on_freq=$event_recurrspec=$uname=
 539                  $Date=$year=$month=$day=$pc_html_or_text=null;
 540                  $is_update = false;
 541                  $pc_event_id = 0;
 542                  // lets wrap all the data into array for passing to submit and preview functions
 543                  $eventdata = compact('event_subject','event_desc','event_sharing','event_category','event_topic',
 544                  'event_startmonth','event_startday','event_startyear','event_starttimeh','event_starttimem','event_startampm',
 545                  'event_endmonth','event_endday','event_endyear','event_endtype','event_dur_hours','event_dur_minutes',
 546                  'event_duration','event_allday','event_location','event_street1','event_street2','event_city','event_state',
 547                  'event_postal','event_location_info','event_contname','event_conttel','event_contemail',
 548                  'event_website','event_fee','event_repeat','event_repeat_freq','event_repeat_freq_type',
 549                  'event_repeat_on_num','event_repeat_on_day','event_repeat_on_freq','event_recurrspec','uname',
 550                  'Date','year','month','day','pc_html_or_text','is_update','pc_event_id');
 551              }
 552          }
 553      }
 554  
 555      $output .= pnModAPIFunc('PostCalendar','admin','buildSubmitForm',$eventdata);
 556      return $output;
 557  }
 558  
 559  function postcalendar_admin_modifyconfig($msg='',$showMenu=true)
 560  {   
 561      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 562      
 563      $output =& new pnHTML();
 564      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
 565      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
 566  
 567      $defaultsURL  = pnModURL(__POSTCALENDAR__,'admin','resetDefaults');
 568      $defaultsText = _EDIT_PC_CONFIG_DEFAULT;
 569      
 570  $jsColorPicker = <<<EOF
 571      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
 572      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
 573      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
 574      <script LANGUAGE="JavaScript">
 575      var cp = new ColorPicker('window');
 576      // Runs when a color is clicked
 577      function pickColor(color) {
 578          field.value = color;
 579      }
 580  
 581      var field;
 582      function pick(anchorname) {
 583          field = document.forms.pcConfig.pcDayHighlightColor;
 584          cp.show(anchorname);
 585      }
 586      </SCRIPT>
 587  EOF;
 588  
 589      $output->SetInputMode(_PNH_VERBATIMINPUT);
 590      $output->Text($jsColorPicker);
 591      if($showMenu) {
 592          $output->Text(postcalendar_adminmenu());
 593      }
 594      
 595      if(!empty($msg)) {
 596          $output->Text('<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">');        
 597          $output->Text("<b>$msg</b>");        
 598          $output->Text('</div></center><br />');        
 599          
 600      }
 601      
 602      $formURL = pnModUrl(__POSTCALENDAR__,'admin','updateconfig');
 603      $output->Text("<form action=\"$formURL\" method=\"post\" enctype=\"application/x-www-form-urlencoded\" name=\"pcConfig\" id=\"pcConfig\">");
 604      $output->Text('<table border="1" cellpadding="5" cellspacing="1">');
 605      $output->Text('<tr><td align="left">'._PC_ADMIN_GLOBAL_SETTINGS,'</td>');
 606      $output->Text("<td nowrap><a href=\"$defaultsURL\">$defaultsText</a></td></tr>");
 607      
 608      $settings = array();
 609      $output->SetOutputMode(_PNH_RETURNOUTPUT);
 610      $i=0;
 611      
 612      // global PostCalendar config options
 613      $settings[$i][] = $output->Text(_PC_NOTIFY_ADMIN);
 614      $settings[$i++][] = $output->FormCheckBox('pcNotifyAdmin', pnModGetVar(__POSTCALENDAR__,'pcNotifyAdmin'));
 615      $settings[$i][] = $output->Text(_PC_NOTIFY_EMAIL);
 616      $settings[$i++][] = $output->FormText('pcNotifyEmail', pnModGetVar(__POSTCALENDAR__,'pcNotifyEmail'));
 617      
 618      $settings[$i][] = $output->Text(_PC_ALLOW_DIRECT_SUBMIT);
 619      $settings[$i++][] = $output->FormCheckBox('pcAllowDirectSubmit', pnModGetVar(__POSTCALENDAR__,'pcAllowDirectSubmit'));
 620      $settings[$i][] = $output->Text(_PC_ALLOW_USER_CALENDAR);
 621      $settings[$i++][] = $output->FormCheckBox('pcAllowUserCalendar', pnModGetVar(__POSTCALENDAR__,'pcAllowUserCalendar'));
 622      $settings[$i][] = $output->Text(_PC_ALLOW_SITEWIDE_SUBMIT);
 623      $settings[$i++][] = $output->FormCheckBox('pcAllowSiteWide', pnModGetVar(__POSTCALENDAR__,'pcAllowSiteWide'));
 624      $settings[$i][] = $output->Text(_PC_LIST_HOW_MANY);
 625      $settings[$i++][] = $output->FormText('pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__,'pcListHowManyEvents'),5);
 626      $settings[$i][] = $output->Text(_PC_TIME24HOURS);
 627      $settings[$i++][] = $output->FormCheckBox('pcTime24Hours', pnModGetVar(__POSTCALENDAR__,'pcTime24Hours'));
 628      $settings[$i][] = $output->Text(_PC_TIME_INCREMENT);
 629      $settings[$i++][] = $output->FormText('pcTimeIncrement', pnModGetVar(__POSTCALENDAR__,'pcTimeIncrement'),5);
 630      $settings[$i][] = $output->Text(_PC_EVENTS_IN_NEW_WINDOW);
 631      $settings[$i++][] = $output->FormCheckBox('pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__,'pcEventsOpenInNewWindow'));
 632      $settings[$i][] = $output->Text(_PC_INTERNATIONAL_DATES);
 633      $settings[$i++][] = $output->FormCheckBox('pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__,'pcUseInternationalDates'));
 634      $settings[$i][] = $output->Text(_PC_EVENT_DATE_FORMAT);
 635      $settings[$i++][] = $output->FormText('pcEventDateFormat', pnModGetVar(__POSTCALENDAR__,'pcEventDateFormat'));
 636      $settings[$i][] = $output->Text(_PC_DISPLAY_TOPICS);
 637      $settings[$i++][] = $output->FormCheckBox('pcDisplayTopics', pnModGetVar(__POSTCALENDAR__,'pcDisplayTopics'));
 638      $settings[$i][] = $output->Text(_PC_FIRST_DAY_OF_WEEK);
 639          $options = array();
 640          $selected = pnModGetVar(__POSTCALENDAR__,'pcFirstDayOfWeek');
 641          $options[0]['id']       = '0';
 642          $options[0]['selected'] = ($selected == 0);
 643          $options[0]['name']     = _PC_SUNDAY;
 644          $options[1]['id']       = '1';
 645          $options[1]['selected'] = ($selected == 1);
 646          $options[1]['name']     = _PC_MONDAY;
 647          $options[2]['id']       = '6';
 648          $options[2]['selected'] = ($selected == 6);
 649          $options[2]['name']     = _PC_SATURDAY;
 650      $settings[$i++][] = $output->FormSelectMultiple('pcFirstDayOfWeek', $options);
 651      $settings[$i][] = $output->Text(_PC_DEFAULT_VIEW);
 652          $options = array();
 653          $selected = pnModGetVar(__POSTCALENDAR__,'pcDefaultView');
 654          $options[0]['id']       = 'day';
 655          $options[0]['selected'] = ($selected == 'day');
 656          $options[0]['name']     = _CAL_DAYVIEW;
 657          $options[1]['id']       = 'week';
 658          $options[1]['selected'] = ($selected == 'week');
 659          $options[1]['name']     = _CAL_WEEKVIEW;
 660          $options[2]['id']       = 'month';
 661          $options[2]['selected'] = ($selected == 'month');
 662          $options[2]['name']     = _CAL_MONTHVIEW;
 663          $options[3]['id']       = 'year';
 664          $options[3]['selected'] = ($selected == 'year');
 665          $options[3]['name']     = _CAL_YEARVIEW;
 666      $settings[$i++][] = $output->FormSelectMultiple('pcDefaultView', $options);
 667      $settings[$i][] = $output->Text(_PC_DAY_HIGHLIGHT_COLOR . ' [<a HREF="#" onClick="pick(\'pick\');return false;" NAME="pick" ID="pick">pick</a>]');
 668      $settings[$i++][] = $output->FormText('pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__,'pcDayHighlightColor'));
 669      $settings[$i][] = $output->Text(_PC_USE_JS_POPUPS);
 670      $settings[$i++][] = $output->FormCheckBox('pcUsePopups', pnModGetVar(__POSTCALENDAR__,'pcUsePopups'));
 671      $settings[$i][] = $output->Text(_PC_USE_CACHE);
 672      $settings[$i++][] = $output->FormCheckBox('pcUseCache', pnModGetVar(__POSTCALENDAR__,'pcUseCache'));
 673      $settings[$i][] = $output->Text(_PC_CACHE_LIFETIME);
 674      $settings[$i++][] = $output->FormText('pcCacheLifetime', pnModGetVar(__POSTCALENDAR__,'pcCacheLifetime'));
 675  
 676      $templatelist = array();
 677      $handle = opendir('modules/'.$pcDir.'/pntemplates');
 678      $hide_list = array('.','..','CVS','compiled','cache');
 679      while($f=readdir($handle))
 680      {   if(!in_array($f,$hide_list) && !ereg("[.]",$f)) {
 681              $templatelist[] = $f;
 682          }
 683      }
 684      closedir($handle); unset($hide_list);
 685      sort($templatelist);
 686      $tcount = count($templatelist);
 687      $settings[$i][] = $output->Text(_PC_DEFAULT_TEMPLATE);
 688          $options = array();
 689          $selected = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
 690          for($t=0;$t<$tcount;$t++) {
 691              $options[$t]['id']       = $templatelist[$t];
 692              $options[$t]['selected'] = ($selected == $templatelist[$t]);
 693              $options[$t]['name']     = $templatelist[$t];
 694          }
 695      $settings[$i++][] = $output->FormSelectMultiple('pcTemplate', $options);
 696  
 697  
 698      $output->SetOutputMode(_PNH_KEEPOUTPUT);
 699      
 700      // Add row
 701      for($i = 0 ; $i < count($settings) ; $i++) {
 702          $output->TableAddRow($settings[$i], 'left');
 703      }
 704      
 705      $output->Text('</table>');
 706      $output->FormSubmit(_PC_ADMIN_SUBMIT);
 707      $output->FormEnd();
 708      
 709      return $output->GetOutput();
 710  }
 711  
 712  function postcalendar_admin_resetDefaults()
 713  {
 714      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 715      
 716      // remove all the PostCalendar variables from the DB
 717      pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
 718      pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
 719      pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
 720      pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
 721      pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
 722      pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
 723      pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
 724      pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
 725      pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
 726      pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
 727      pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
 728      pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
 729      pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
 730      pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
 731      pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
 732      pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
 733      pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
 734      pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
 735      pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
 736      
 737      // PostCalendar Default Settings
 738      pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours',              '0');
 739      pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow',    '0');
 740      pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates',    '0');
 741      pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek',           '0');
 742      pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor',        '#FF0000');
 743      pnModSetVar(__POSTCALENDAR__, 'pcUsePopups',                '1');
 744      pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics',            '0');
 745      pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit',        '0');
 746      pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents',        '15');
 747      pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement',            '15');
 748      pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide',            '0');
 749      pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar',        '1');
 750      pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat',            '%Y-%m-%d');
 751      pnModSetVar(__POSTCALENDAR__, 'pcTemplate',                 'default');
 752      pnModSetVar(__POSTCALENDAR__, 'pcUseCache',                 '1');
 753      pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime',             '3600');
 754      pnModSetVar(__POSTCALENDAR__, 'pcDefaultView',                 'month');
 755      pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin',                 '0');
 756      pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail',                 pnConfigGetVar('adminmail'));
 757      
 758      $tpl =& new pcSmarty();
 759      $tpl->clear_all_cache();
 760      
 761      return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED_DEFAULTS.'</center>');
 762  }
 763  
 764  function postcalendar_admin_updateconfig()
 765  {
 766      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 767      
 768      list($pcTime24Hours, $pcEventsOpenInNewWindow, $pcUseInternationalDates,
 769           $pcFirstDayOfWeek, $pcDayHighlightColor, $pcUsePopups,
 770           $pcAllowDirectSubmit, $pcListHowManyEvents, $pcDisplayTopics,
 771           $pcEventDateFormat, $pcTemplate, $pcAllowSiteWide,
 772           $pcAllowUserCalendar, $pcTimeIncrement,$pcUseCache, $pcCacheLifetime,
 773           $pcDefaultView, $pcNotifyAdmin, $pcNotifyEmail) = pnVarCleanFromInput('pcTime24Hours',
 774           'pcEventsOpenInNewWindow', 'pcUseInternationalDates', 'pcFirstDayOfWeek',
 775           'pcDayHighlightColor', 'pcUsePopups', 'pcAllowDirectSubmit',
 776           'pcListHowManyEvents', 'pcDisplayTopics', 'pcEventDateFormat',
 777           'pcTemplate', 'pcAllowSiteWide', 'pcAllowUserCalendar', 'pcTimeIncrement',
 778           'pcUseCache', 'pcCacheLifetime', 'pcDefaultView', 'pcNotifyAdmin', 'pcNotifyEmail');
 779                                                     
 780      // make sure we enter something into the DB                                               
 781      if(!isset($pcTime24Hours))           { $pcTime24Hours = '0'; }
 782      if(!isset($pcEventsOpenInNewWindow)) { $pcEventsOpenInNewWindow='0'; }
 783      if(!isset($pcUseInternationalDates)) { $pcUseInternationalDates='0'; }
 784      if(!isset($pcFirstDayOfWeek))        { $pcFirstDayOfWeek='0'; }
 785      if(!isset($pcUsePopups))             { $pcUsePopups='0'; }
 786      if(!isset($pcAllowDirectSubmit))     { $pcAllowDirectSubmit='0'; }
 787      if(!isset($pcDisplayTopics))         { $pcDisplayTopics='0'; }
 788      if(!isset($pcTemplate))              { $pcTemplate='default'; }
 789      if(!isset($pcAllowSiteWide))         { $pcAllowSiteWide='0'; }
 790      if(!isset($pcAllowUserCalendar))     { $pcAllowUserCalendar='0'; }
 791      if(!isset($pcUseCache))              { $pcUseCache='0'; }
 792      if(!isset($pcDefaultView))              { $pcDefaultView='month'; }
 793      if(empty($pcCacheLifetime))          { $pcCacheLifetime='3600'; }
 794      if(empty($pcDayHighlightColor))      { $pcDayHighlightColor='#ff0000'; }
 795      if(empty($pcListHowManyEvents))      { $pcListHowManyEvents='15'; }
 796      if(empty($pcEventDateFormat))         { $pcEventDateFormat='%Y-%m-%d'; }
 797      if(empty($pcTimeIncrement))          { $pcTimeIncrement='15'; }
 798      if(empty($pcNotifyAdmin))              { $pcNotifyAdmin='0'; }
 799      if(empty($pcNotifyEmail))            { $pcNotifyEmail=pnConfigGetVar('adminmail'); }
 800      
 801      // delete the old vars - we're doing this because PostNuke variable 
 802      // handling sometimes has old values in the $GLOBALS we need to clear
 803      pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
 804      pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
 805      pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
 806      pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
 807      pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
 808      pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
 809      pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
 810      pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
 811      pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
 812      pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
 813      pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
 814      pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
 815      pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
 816      pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
 817      pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
 818      pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
 819      pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
 820      pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
 821      pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
 822      
 823      // set the new variables
 824      pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours',           $pcTime24Hours);
 825      pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', $pcEventsOpenInNewWindow);
 826      pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', $pcUseInternationalDates);
 827      pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek',         $pcFirstDayOfWeek);
 828      pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor',     $pcDayHighlightColor);
 829      pnModSetVar(__POSTCALENDAR__, 'pcUsePopups',             $pcUsePopups);
 830      pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit',     $pcAllowDirectSubmit);
 831      pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents',     $pcListHowManyEvents);
 832      pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics',         $pcDisplayTopics);
 833      pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat',       $pcEventDateFormat);
 834      pnModSetVar(__POSTCALENDAR__, 'pcTemplate',              $pcTemplate);
 835      pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide',         $pcAllowSiteWide);
 836      pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar',     $pcAllowUserCalendar);
 837      pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement',         $pcTimeIncrement);
 838      pnModSetVar(__POSTCALENDAR__, 'pcDefaultView',              $pcDefaultView);
 839      pnModSetVar(__POSTCALENDAR__, 'pcUseCache',                  $pcUseCache);
 840      pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime',         $pcCacheLifetime);
 841      pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin',              $pcNotifyAdmin);
 842      pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail',              $pcNotifyEmail);
 843       
 844      $tpl =& new pcSmarty();
 845      $tpl->clear_all_cache();
 846      
 847      return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED.'</center>');
 848  }
 849  
 850  function postcalendar_admin_categories($msg='',$e='')
 851  {
 852      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 853      
 854      $output =& new pnHTML();
 855      $output->SetInputMode(_PNH_VERBATIMINPUT);
 856      
 857      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
 858      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
 859  $jsColorPicker = <<<EOF
 860      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
 861      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
 862      <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
 863      <script LANGUAGE="JavaScript">
 864      var cp = new ColorPicker('window');
 865      // Runs when a color is clicked
 866      function pickColor(color) {
 867          field.value = color;
 868      }
 869  
 870      var field;
 871      function pick(anchorname,target) {
 872          field = this.document.forms.cats.elements[target];
 873          cp.show(anchorname);
 874      }
 875      </SCRIPT>
 876  EOF;
 877      
 878      $output->Text($jsColorPicker);
 879      $output->Text(postcalendar_adminmenu());
 880      
 881      if(!empty($e)) { 
 882          $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
 883          $output->Text('<center><b>'.$e.'</b></center>');
 884          $output->Text('</div><br />');
 885      }
 886      
 887      if(!empty($msg)) { 
 888          $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
 889          $output->Text('<center><b>'.$msg.'</b></center>');
 890          $output->Text('</div><br />');
 891      }
 892      
 893      $cats = pnModAPIFunc(__POSTCALENDAR__,'admin','getCategories');
 894      if(!is_array($cats)) {
 895          $output->Text($cats);
 896          return $output->GetOutput();
 897      }
 898      
 899      $output->Text('<form name="cats" method="post" action="'.pnModURL(__POSTCALENDAR__,'admin','categoriesConfirm').'">');
 900      $output->Text('<table border="1" cellpadding="5" cellspacing="0">');
 901      $output->Text('<tr><th>'._PC_CAT_DELETE.'</th><th>'._PC_CAT_NAME.'</th><th>'._PC_CAT_DESC.'</th><th>'._PC_CAT_COLOR.'</th></tr>');
 902      $i = 0;
 903      foreach($cats as $cat) {
 904          $output->Text('<tr>');
 905              $output->Text('<td valign="top" align="left">');
 906                  $output->FormHidden('id[]',$cat['id']);
 907                  $output->FormCheckbox('del[]',false,$cat['id']);
 908              $output->Text('</td>');
 909              $output->Text('<td valign="top" align="left">');
 910                  $output->FormText('name[]',$cat['name'],20);
 911              $output->Text('</td>');
 912              $output->Text('<td valign="top" align="left">');
 913                  $output->FormTextarea('desc[]',$cat['desc'],3,20);
 914              $output->Text('</td>');
 915              $output->Text('<td valign="top" align="left">');
 916                  $output->FormText('color[]',$cat['color'],10);
 917                  $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\''.($i+4).'\'); return false;" NAME="pick" ID="pick">pick</a>]');
 918              $output->Text('</td>');
 919          $output->Text('</tr>');
 920          $i+=5;
 921      }
 922          $output->Text('<tr>');
 923              $output->Text('<td valign="top" align="left">');
 924                  $output->Text(_PC_CAT_NEW);
 925              $output->Text('</td>');
 926              $output->Text('<td valign="top" align="left">');
 927                  $output->FormText('newname','',20);
 928              $output->Text('</td>');
 929              $output->Text('<td valign="top" align="left">');
 930                  $output->FormTextarea('newdesc','',3,20);
 931              $output->Text('</td>');
 932              $output->Text('<td valign="top" align="left">');
 933                  $output->FormText('newcolor','',10);
 934                  $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\'newcolor\');return false;" NAME="pick" ID="pick">pick</a>]');
 935              $output->Text('</td>');
 936          $output->Text('</tr>');
 937      $output->Text('</table>');
 938      $output->FormSubmit(_PC_ADMIN_SUBMIT);
 939      $output->FormEnd();
 940      
 941      return $output->GetOutput();
 942  }
 943  function postcalendar_admin_categoriesConfirm()
 944  {   
 945      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 946      
 947      $output =& new pnHTML();
 948      $output->SetInputMode(_PNH_VERBATIMINPUT);
 949      $output->Text(postcalendar_adminmenu());
 950      
 951      list($id,$del,$name,$desc,$color,
 952           $newname,$newdesc,$newcolor) = pnVarCleanFromInput('id','del','name','desc','color',
 953                                                              'newname','newdesc','newcolor');
 954     
 955      if(is_array($del)) {                                                
 956          $dels = implode(',',$del);
 957          $delText = _PC_DELETE_CATS . $dels .'.';
 958      }
 959      $output->FormStart(pnModURL(__POSTCALENDAR__,'admin','categoriesUpdate'));
 960      $output->Text(_PC_ARE_YOU_SURE);
 961      $output->Linebreak(2);
 962      // deletions
 963      if(isset($delText)) {
 964          $output->FormHidden('dels',$dels);
 965          $output->Text($delText);
 966          $output->Linebreak();
 967      }
 968      if(!empty($newname)) {
 969          $output->FormHidden('newname',$newname);
 970          $output->FormHidden('newdesc',$newdesc);
 971          $output->FormHidden('newcolor',$newcolor);
 972          $output->Text(_PC_ADD_CAT . $newname .'.');
 973          $output->Linebreak();
 974      }
 975      $output->Text(_PC_MODIFY_CATS);
 976      $output->FormHidden('id',serialize($id));
 977      $output->FormHidden('del',serialize($del));
 978      $output->FormHidden('name',serialize($name));
 979      $output->FormHidden('desc',serialize($desc));
 980      $output->FormHidden('color',serialize($color));
 981      $output->Linebreak();
 982      $output->FormSubmit(_PC_CATS_CONFIRM);
 983      $output->FormEnd();
 984                 
 985      return $output->GetOutput();
 986  
 987  }
 988  function postcalendar_admin_categoriesUpdate()
 989  {   
 990      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
 991      
 992      $output =& new pnHTML();
 993      $output->SetInputMode(_PNH_VERBATIMINPUT);
 994      
 995      list($dbconn) = pnDBGetConn();
 996      $pntable = pnDBGetTables();
 997      
 998      list($id,$dels,$del,$name,$desc,$color,
 999           $newname,$newdesc,$newcolor) = pnVarCleanFromInput('id','dels','del','name','desc','color',
1000                                                              'newname','newdesc','newcolor');
1001     
1002      $id = unserialize($id);
1003      $del = unserialize($del);
1004      $name = unserialize($name);
1005      $desc = unserialize($desc);
1006      $color = unserialize($color);
1007      
1008      $modID = $modName = $modDesc = $modColor = array();
1009      
1010      if(isset($id)) {
1011          foreach($id as $k=>$i) {
1012              $found = false;
1013              if(count($del)) {
1014                  foreach($del as $d) {
1015                      if($i == $d) {
1016                          $found = true;
1017                          break;
1018                      }
1019                  }  
1020              } 
1021              if(!$found) {
1022                  array_push($modID,$i);
1023                  array_push($modName,$name[$k]);
1024                  array_push($modDesc,$desc[$k]);
1025                  array_push($modColor,$color[$k]);
1026              }
1027          }
1028      }
1029  
1030      
1031      $updates = array();
1032      foreach($modID as $k=>$id) {
1033          array_push($updates,"UPDATE $pntable[postcalendar_categories] 
1034                               SET pc_catname='".pnVarPrepForStore($modName[$k])."',
1035                                   pc_catdesc='".pnVarPrepForStore($modDesc[$k])."',
1036                                   pc_catcolor='".pnVarPrepForStore($modColor[$k])."'
1037                               WHERE pc_catid=$id");
1038      }
1039      
1040      $delete = "DELETE FROM $pntable[postcalendar_categories] WHERE pc_catid IN ($dels)";
1041      $e =  $msg = '';
1042      if(!pnModAPIFunc(__POSTCALENDAR__,'admin','updateCategories',array('updates'=>$updates))) {
1043          $e .= 'UPDATE FAILED';
1044      }
1045      if(isset($dels)) {
1046          if(!pnModAPIFunc(__POSTCALENDAR__,'admin','deleteCategories',array('delete'=>$delete))) {
1047              $e .= 'DELETE FAILED';
1048          }
1049      }
1050      if(isset($newname)) {
1051          if(!pnModAPIFunc(__POSTCALENDAR__,'admin','addCategories',array('name'=>$newname,'desc'=>$newdesc,'color'=>$newcolor))) {
1052              $e .= 'INSERT FAILED';
1053          }
1054      }
1055      if(empty($e)) { $msg = 'DONE'; }
1056      $output->Text(postcalendar_admin_categories($msg,$e));
1057      return $output->GetOutput();
1058  }
1059  /**
1060   * Main administration menu
1061   */
1062  function postcalendar_adminmenu($upgraded=false)
1063  {
1064      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1065      
1066      pnThemeLoad(pnUserGetTheme());
1067      // get the theme globals :: is there a better way to do this?
1068      global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6;
1069      global $textcolor1, $textcolor2;
1070      
1071      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1072      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1073      
1074      @define('_AM_VAL',           1);
1075      @define('_PM_VAL',           2);
1076      
1077      @define('_EVENT_APPROVED',   1);
1078      @define('_EVENT_QUEUED',     0);
1079      @define('_EVENT_HIDDEN',    -1);
1080      
1081      $adminURL     = pnModURL(__POSTCALENDAR__,'admin','');
1082      $settingsURL  = pnModURL(__POSTCALENDAR__,'admin','modifyconfig');
1083      $categoryURL  = pnModURL(__POSTCALENDAR__,'admin','categories');
1084      $submitURL    = pnModURL(__POSTCALENDAR__,'admin','submit');
1085      $approvedURL  = pnModURL(__POSTCALENDAR__,'admin','listapproved');
1086      $hiddenURL    = pnModURL(__POSTCALENDAR__,'admin','listhidden');
1087      $queuedURL    = pnModURL(__POSTCALENDAR__,'admin','listqueued');
1088      $cacheURL     = pnModURL(__POSTCALENDAR__,'admin','clearCache');
1089      $systemURL    = pnModURL(__POSTCALENDAR__,'admin','testSystem');
1090      
1091      $adminText    = _POSTCALENDAR;
1092      $settingsText = _EDIT_PC_CONFIG_GLOBAL;
1093      $categoryText = _EDIT_PC_CONFIG_CATEGORIES;
1094      $submitText   = _PC_CREATE_EVENT;
1095      $approvedText = _PC_VIEW_APPROVED;
1096      $hiddenText   = _PC_VIEW_HIDDEN;
1097      $queuedText   = _PC_VIEW_QUEUED;
1098      $cacheText    = _PC_CLEAR_CACHE;
1099      $cacheText    = _PC_CLEAR_CACHE;
1100      $systemText   = _PC_TEST_SYSTEM;
1101      
1102      // check for upgrade
1103      $upgrade = '';
1104      if($upgraded === false) {
1105          $upgrade = pc_isNewVersion();
1106      }
1107      
1108  
1109  $output = <<<EOF
1110  <table border="0" cellpadding="1" cellspacing="0" width="100%" bgcolor="$bgcolor2"><tr><td>
1111  <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1112      <tr>
1113          <td align="left" valign="middle"><a href="$adminURL"><img 
1114              border="0" src="modules/$pcDir/pnimages/admin.gif"></a></td>
1115          <td width="100%" align="left" valign="middle">
1116              <table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="$bgcolor2">
1117              <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1118                  <tr>
1119                      <td nowrap>
1120                          <a href="$settingsURL">$settingsText</a> |
1121                          <a href="$submitURL">$submitText</a> |
1122                          <a href="$cacheURL">$cacheText</a> |
1123                          <a href="$systemURL">$systemText</a> |
1124                          <a href="$categoryURL">$categoryText</a> |
1125                          <a href="$queuedURL">$queuedText</a> |
1126                          <a href="$approvedURL">$approvedText</a> |
1127                          <a href="$hiddenURL">$hiddenText</a>
1128                          $upgrade
1129                  </tr>
1130              </table>
1131              </td></tr></table>
1132          </td>
1133      </tr>
1134  </table>
1135  </td></tr></table>
1136  <br />
1137  EOF;
1138  // Return the output that has been generated by this function
1139  return $output;
1140  }
1141  
1142  function postcalendar_admin_clearCache()
1143  {
1144      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1145      
1146      $tpl =& new pcSmarty();
1147      $tpl->clear_all_cache();
1148      $tpl->clear_compiled_tpl();
1149      
1150      return postcalendar_admin_modifyconfig('<center>'._PC_CACHE_CLEARED.'</center>');
1151  }
1152  
1153  function pc_isNewVersion()
1154  {
1155      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1156      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1157      @include("modules/$pcDir/pnversion.php");
1158      
1159      if($pcModInfo['version'] <> $modversion['version']) {
1160          $upgradeURL   = pnModURL(__POSTCALENDAR__,'admin','upgrade');
1161          $upgradeText  = "Upgrade PostCalendar $pcModInfo[version] to $modversion[version]";
1162          $upgrade = "<br /><br />[ <a href=\"$upgradeURL\">$upgradeText</a> ]";
1163      } else {
1164          $upgrade = '';
1165      }
1166      
1167      return $upgrade;
1168  }
1169  
1170  // UPGRADE WORKAROUND SCRIPT - POSTNUKE BUG
1171  function postcalendar_admin_upgrade()
1172  {
1173      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1174      
1175      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1176      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1177      @include("modules/$pcDir/pnversion.php");
1178      @include("modules/$pcDir/pninit.php");
1179      
1180      $result = postcalendar_upgrade($pcModInfo['version']);
1181      
1182      if($result === false) {
1183          $output  = postcalendar_adminmenu(false);
1184          $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1185          $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b></center>';
1186          $output .= '</div><br />';
1187          return $output;
1188      }
1189      
1190      // if we've gotten this far, then it's time to increment the version in the db
1191      list($dbconn) = pnDBGetConn();
1192      $pntable = pnDBGetTables();
1193      $modulestable = $pntable['modules'];
1194      $modulescolumn = &$pntable['modules_column'];
1195      
1196      // Get module ID
1197      $modulestable = $pntable['modules'];
1198      $modulescolumn = &$pntable['modules_column'];
1199      $query = "SELECT $modulescolumn[id]
1200                FROM $modulestable
1201                WHERE $modulescolumn[name] = '". pnVarPrepForStore(__POSTCALENDAR__)."'";
1202      $result = $dbconn->Execute($query);
1203  
1204      if ($result->EOF) { die("Failed to get module ID"); }
1205  
1206      list($mid) = $result->fields;
1207      $result->Close();
1208      
1209      $sql = "UPDATE $modulestable
1210              SET $modulescolumn[version] = '".pnVarPrepForStore($modversion['version'])."',
1211                  $modulescolumn[state] = '".pnVarPrepForStore(_PNMODULE_STATE_ACTIVE)."'
1212              WHERE $modulescolumn[id] = '".pnVarPrepForStore($mid)."'";
1213      
1214      // upgrade did not succeed
1215      if($dbconn->Execute($sql) === false) { 
1216          $output  = postcalendar_adminmenu(false);
1217          $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1218          $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b><br />';
1219          $output .= $dbconn->ErrorMsg();
1220          $output .= '</center>';
1221          $output .= '</div><br />';
1222      }
1223      $output  = postcalendar_adminmenu(true);
1224      $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
1225      $output .= '<center><b>CONGRATULATIONS :: MODULE UPGRADE SUCCEEDED</b></center>';
1226      $output .= '</div><br />';
1227      return $output;
1228  }
1229  
1230  function postcalendar_admin_testSystem()
1231  {
1232      global $bgcolor1,$bgcolor2;
1233      
1234      if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1235     
1236      $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1237      $pcDir = pnVarPrepForOS($modinfo['directory']);
1238      $version = $modinfo['version'];
1239      unset($modinfo);
1240      
1241      $tpl =& new pcSmarty();
1242      $infos = array();
1243      
1244      if(phpversion() >= '4.1.0') {
1245          $__SERVER =& $_SERVER;
1246          $__ENV    =& $_ENV;
1247      } else {
1248          $__SERVER =& $HTTP_SERVER_VARS;
1249          $__ENV    =& $HTTP_ENV_VARS;
1250      }
1251      
1252      if(defined('_PN_VERSION_NUM')) {
1253          $pnVersion = _PN_VERSION_NUM;
1254      } else {
1255          $pnVersion = pnConfigGetVar('Version_Num');
1256      }
1257      
1258      array_push($infos, array('CMS Version', $pnVersion));
1259      array_push($infos, array('Sitename', pnConfigGetVar('sitename')));
1260      array_push($infos, array('url', pnGetBaseURL()));
1261      array_push($infos, array('PHP Version', phpversion()));
1262      if ((bool) ini_get('safe_mode')) {
1263            $safe_mode = "On";
1264      } else {
1265            $safe_mode = "Off";
1266      }
1267      array_push($infos, array('PHP safe_mode', $safe_mode));
1268      if ((bool) ini_get('safe_mode_gid')) {
1269            $safe_mode_gid = "On";
1270      } else {
1271            $safe_mode_gid = "Off";
1272      }
1273      array_push($infos, array('PHP safe_mode_gid', $safe_mode_gid));
1274      $base_dir = ini_get('open_basedir');
1275      if(!empty($base_dir)) {
1276          $open_basedir = "$base_dir";
1277      } else {
1278          $open_basedir = "NULL";
1279      }
1280      array_push($infos, array('PHP open_basedir', $open_basedir));
1281      array_push($infos, array('SAPI', php_sapi_name()));
1282      array_push($infos, array('OS', php_uname()));
1283      array_push($infos, array('WebServer', $__SERVER['SERVER_SOFTWARE']));
1284      array_push($infos, array('Module dir', "modules/$pcDir"));
1285  
1286      $modversion = array();
1287      include  "modules/$pcDir/pnversion.php";
1288      
1289      $error = '';
1290      if ($modversion['version'] != $version) {
1291            $error  = '<br /><div style=\"color: red;\">';
1292            $error .= "new version $modversion[version] installed but not updated!";
1293            $error .= '</div>';
1294      }
1295      array_push($infos, array('Module version', $version . " $error"));
1296      array_push($infos, array('smarty version', $tpl->_version));
1297      array_push($infos, array('smarty location',  SMARTY_DIR));
1298      array_push($infos, array('smarty template dir', $tpl->template_dir));
1299  
1300      $info = $tpl->compile_dir;
1301      $error = '';
1302      if (!file_exists($tpl->compile_dir)) {
1303            $error .= " compile dir doesn't exist! [$tpl->compile_dir]<br />";
1304      } else {
1305            // dir exists -> check if it's writeable
1306            if (!is_writeable($tpl->compile_dir)) {
1307               $error .= " compile dir not writeable! [$tpl->compile_dir]<br />";
1308            }
1309      }
1310      if (strlen($error) > 0) {
1311            $info .= "<br /><div style=\"color: red;\">$error</div>";
1312      }
1313      array_push($infos, array('smarty compile dir',  $info));
1314      
1315      $info = $tpl->cache_dir;
1316      $error = "";
1317      if (!file_exists($tpl->cache_dir)) {
1318            $error .= " cache dir doesn't exist! [$tpl->cache_dir]<br />";
1319      } else {
1320            // dir exists -> check if it's writeable
1321            if (!is_writeable($tpl->cache_dir)) {
1322               $error .= " cache dir not writeable! [$tpl->cache_dir]<br />";
1323            }
1324      }
1325      if (strlen($error) > 0) {
1326            $info .= "<br /><div style=\"color: red;\">$error</div>";
1327      }
1328      array_push($infos, array('smarty cache dir',  $info));
1329  
1330      $output  = postcalendar_adminmenu();
1331      $output .= '<table border="1" cellpadding="3" cellspacing="1">';
1332      $output .= '  <tr><th align="left">Name</th><th align="left">Value</th>';
1333      $output .= '</tr>';
1334      foreach ($infos as $info) {
1335          $output.= '<tr><td ><b>' . pnVarPrepHTMLDisplay($info[0]) . '</b></td>';
1336            $output.= '<td>' . pnVarPrepHTMLDisplay($info[1]) . '</td></tr>';
1337      }
1338      $output .= '</table>';
1339      $output .= '<br /><br />';
1340      $output .= postcalendar_admin_modifyconfig('',false);
1341      return $output;
1342  }
1343  ?>


Generated: Wed Feb 16 22:40:07 2005 Cross-referenced by PHPXref 0.6