Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/Clock/Clock.php - 324 lines - 17837 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /**
   4  * Name:      Clock.php
   5  * App:       Clock
   6  * Desc:      Allows the user to select and customize four types of clocks.
   7  * Creator:   Jason Yoder <jasonay@goshen.edu>
   8  */
   9  
  10  class Clock extends App
  11      {
  12  
  13      function getContent() 
  14          {
  15          $clockcode = isset($this->settingsVars['clocktype']) ? $this->settingsVars['clocktype'] : '<simple>';
  16          if ($clockcode == '<analog>')
  17              {
  18              if ( $this->settingsVars['clocksize'] == 'maximum')
  19                  $this->settingsVars['clocksize'] = 200;
  20              else
  21                  {    
  22                  if ($this->settingsVars['clocksize'] < 200)
  23                      $this->settingsVars['clocksize'] = $this->settingsVars['clocksize'];
  24                  else
  25                      $this->settingsVars['clocksize'] = 200;
  26                  }
  27  
  28              if ($this->settingsVars['clocksize'] == 0 )
  29                  {
  30                  $this->settingsVars['clocksize'] = 200;
  31                  print("Please re-register your Clock Application from the site settings menu." );
  32                  }
  33              
  34              //dont allow the clock to get bigger than 200 or it will get very slow
  35              if ($this->settingsVars['clocksize'] > 200) $this->settingsVars['clocksize'] = 200;
  36              
  37              $this->addHeader('
  38    <style type="text/css">
  39    #cl1 {
  40    background-color:' . $this->settingsVars['bgcolor'] . ';
  41    text-align:left;
  42    font-size:' . $this->settingsVars['fontsize'] . 'px;
  43    color:' . $this->settingsVars['fontcolor'] . ';
  44    }
  45    </style>');
  46              
  47              return '
  48              <div style=width:100% id=' . $this->paramName('clocknode') . '>&nbsp;</div>
  49              <div>                
  50              <script type="text/javascript" language="Javascript1.2">
  51              var standard = new Array(\'\',\'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'10\', \'11\', \'12\');
  52              var roman = new Array(\'\',\'I\', \'II\', \'III\', \'IV\', \'V\', \'VI\', \'VII\', \'VIII\', \'IX\', \'X\', \'XI\', \'XII\');
  53              var w = new JSClock(\'cl1\',\''.$this->settingsVars['secondcolor'].'\'
  54              ,'.$this->settingsVars['clocksize'].'
  55              ,\''.$this->settingsVars['minutecolor'].'\'
  56              ,\''.$this->settingsVars['hourcolor'].'\');
  57              w.drawC(\''.$this->settingsVars['circlecolor'].'\');
  58              w.setHours('.$this->settingsVars['fonttype'].','.$this->settingsVars['fonttype'].');'.
  59              //set hours can be configured to allow to different sets of number arrays for AM and PM 
  60              //not currently being implemented
  61             'w.setParent(document.getElementById(\''.$this->paramName('clocknode').'\'));
  62              w.start();
  63              </script></div>';
  64              }
  65          else if($clockcode == '<countdown>')
  66              {
  67              $timecode = $this->settingsVars['date'].', '.$this->settingsVars['hours'].':'.$this->settingsVars['minutes'].':'.$this->settingsVars['seconds'];
  68              $event = $this->settingsVars['event'];
  69              $event = str_replace('\'','&#39;', $event);
  70              $expiredmessage = $this->settingsVars['expiredmessage'];
  71              $expiredmessage = str_replace('\'','&#39;', $expiredmessage);
  72              return '<div id=' . $this->paramName('divcode') . '>&nbsp;</div>'.
  73              '<div><br>'.
  74              '<script type="text/javascript" language="Javascript1.2"> start(\''.$this->paramName('divcode').'\',\'' . $timecode . '\',\'' . $event . '\',\'' . $expiredmessage . '\'); </SCRIPT></div>';
  75              }
  76          else
  77              {
  78              //next line prevents an error if someone uses " o'clock "
  79              $clockcode = str_replace("\\", "\\\\", $clockcode);
  80              $clockcode = str_replace('\'','&#39;', $clockcode);
  81              $clockcode = str_replace("\r\n", "<br />", $clockcode);
  82              return ('<div id='.$this->paramName('spanid2').'></div><div id='.$this->paramName('spanid').'></div><script type="text/javascript" language="Javascript1.2">show_clock(\''.$clockcode.'\',\''.$this->paramName('spanid').'\');</script>');
  83              }
  84          }
  85  
  86      function onSave()
  87              {
  88              //takes care of issue of someone manually placing an analog, countdown, or simple tag in custom textbox
  89  
  90              if ($this->httpVars['type'] == 'custom')
  91                  {
  92                  $this->httpVars['clocktype'] = str_replace('<analog>','', $this->httpVars['clocktype']);
  93                  $this->httpVars['clocktype'] = str_replace('<simple>','', $this->httpVars['clocktype']);
  94                  $this->httpVars['clocktype'] = str_replace('<countdown>','', $this->httpVars['clocktype']);
  95                  }
  96              $this->settingsVars['type'] = @$this->httpVars['type'];
  97              $this->settingsVars['clocktype'] = @$this->httpVars['clocktype'];
  98              $this->settingsVars['hours'] = @$this->httpVars['hours'];
  99              $this->settingsVars['seconds'] = @$this->httpVars['seconds'];
 100              $this->settingsVars['minutes'] = @$this->httpVars['minutes'];
 101              $this->settingsVars['date'] = @$this->httpVars['date'];
 102              $this->settingsVars['event'] = @$this->httpVars['event'];
 103              $this->settingsVars['hourcolor'] = @$this->httpVars['hourcolor'];
 104              $this->settingsVars['minutecolor'] = @$this->httpVars['minutecolor'];
 105              $this->settingsVars['secondcolor'] = @$this->httpVars['secondcolor'];
 106              $this->settingsVars['circlecolor'] = @$this->httpVars['circlecolor'];
 107              $this->settingsVars['bgcolor'] = @$this->httpVars['bgcolor'];
 108              $this->settingsVars['fontcolor'] = @$this->httpVars['fontcolor'];
 109              $this->settingsVars['fontsize'] = @$this->httpVars['fontsize'];
 110              $this->settingsVars['clocksize'] = @$this->httpVars['clocksize'];
 111              $this->settingsVars['fonttype'] = @$this->httpVars['fonttype'];
 112              $this->settingsVars['customstore'] = @$this->httpVars['customstore'];      
 113              $this->settingsVars['expiredmessage'] = @$this->httpVars['expiredmessage'];
 114              $this->saveSettings($this->settingsVars);
 115              }
 116  
 117      function getConfig()
 118          {
 119          $f = FormWidget::init();
 120          $f->section();
 121          $f->name($this->paramName('clock'));
 122          if (!isset($this->settingsVars['clocktype']) )
 123              {
 124              $this->settingsVars['type'] = 'simple';
 125              $this->settingsVars['clocktype'] = '<simple>';
 126              }
 127              
 128          //customstore is a never visible textbox used to keep track of last custom setup for restoring upon loading
 129          $f->text('customstore',$this->settingsVars['customstore'], 100, array('id' => $this->paramName('customstore'),
 130          'style' => ( 'display:none;' ) ) );
 131          
 132          $attrs = array('onclick' => 'functionVisibility(this.value
 133                                   ,\''.$this->paramName('clocktype').'\',\''.$this->paramName('countDiv').'\', \''
 134                                   .$this->paramName('analogDiv').'\', \''.$this->paramName('customDiv').'\',\''
 135                                   .$this->paramName('customstore').'\')' );
 136          $types1 = array('analog' => '<b>Analog Clock</b><br>A standalone feature that provides an analog clock displaying seconds, minutes, and hours<br><br>');
 137          $types2 = array('countdown' =>'<b>Count Down</b><br>A standalone feature that gives user specified time increments until an event occurs<br><br>');
 138          $types3 = array('simple' => '<b>Simple Clock</b><br>A standalone feature which provide most information in a standardized format<br>',
 139                         'custom' => '<b>Custom Clock</b><br>A feature which allows any of the different time increments as well as html');
 140          $type = @$this->params['type'] ? $this->params['type'] : 'simple';
 141  
 142          //ensure proper spacing
 143          $f->html('<tr><td colspan=2>');
 144          $f->radio('type', $types1, $type, '', '', $attrs);
 145  
 146          if ( $this->settingsVars['clocktype'] == '<analog>')
 147              {
 148              $f->html('<div id='.$this->paramName('analogDiv').' style="display:block;">'); 
 149              }
 150          else
 151              {
 152              $f->html('<div id='.$this->paramName('analogDiv').' style="display:none;">');
 153              }
 154          //set defaults to black
 155          $f->html('<table><tr><td>Select hour hand color:</td><td>');
 156          $f->color('hourcolor', @$this->params['hourcolor'] ? $this->params['hourcolor'] : 'black', 'Select hour hand color:' );        
 157          $f->html('</td></tr>');
 158          
 159          $f->html('<tr><td>Select minute hand color:</td><td>');
 160          $f->color('minutecolor', @$this->params['minutecolor'] ? $this->params['minutecolor'] : 'black', 'Select minute hand color:' );        
 161          $f->html('</td></tr>');
 162          
 163          $f->html('<tr><td>Select second hand color:</td><td>');
 164          $f->color('secondcolor', @$this->params['secondcolor'] ? $this->params['secondcolor'] : 'black', 'Select second hand color:' );        
 165          $f->html('</td></tr>');
 166                  
 167          $f->html('<tr><td>Select outer circle color:</td><td>');
 168          $f->color('circlecolor', @$this->params['circlecolor'] ? $this->params['circlecolor'] : 'black', 'Select outer circle color:' );        
 169          $f->html('</td></tr>');
 170          
 171          $f->html('<tr><td>Select background color:</td><td>');
 172          $f->color('bgcolor', $this->settingsVars['bgcolor'], 'Select background color:' );        
 173          $f->html('</td></tr>');
 174  
 175          $f->html('<tr><td>Select font color:</td><td>');
 176          $f->color('fontcolor', @$this->params['fontcolor'] ? $this->params['fontcolor'] : 'black', 'Select font color:' );        
 177          $f->html('</td></tr>');
 178  
 179          $fontsize = array( '6' => '6', '8' => '8', '10' => '10', '12' => '12', '14' => '14', '16' => '16', '18' => '18', 
 180                            '20' => '20', '22' => '22', '24' => '24', '26' => '26', '28' => '28', '30' => '30', '32' => '32', 
 181                            '34' => '34', '36' => '36', '38' => '38', '40' => '40' );
 182          $f->html('<tr><td>Select font size:</td><td>');
 183          $f->dropdown('fontsize', $fontsize, @$this->params['fontsize'], '12');
 184          $f->html('</td></tr>');
 185  
 186          $fonttype = array( 'standard' => 'Standard   1, 2, 3,  ect.', 'roman' => 'Roman Numerals   I, II, III,  ect.');        
 187          $f->html('<tr><td>Select font type:</td><td>');
 188          $f->dropdown('fonttype', $fonttype, @$this->params['fonttype'], '0');        
 189          $f->html('</td></tr>');
 190  
 191          //this table may be modified for enhanced usability if people suggest it
 192          $clocksize = array( '20' => '20', '30' => '30', '40' => '40', '50' => '50', '60' => '60', '80' => '80', 
 193                              '100' => '100', '120' => '120', '140' => '140', '160' => '160', '180' => '180', 
 194                              'maximum' => 'Maximum Width' );
 195          $f->html('<tr><td>Select clock size:</td><td>');
 196          $f->dropdown('clocksize', $clocksize, @$this->params['clocksize'], 'maximum');
 197          
 198          
 199          $f->html('</td></tr></table>');
 200          $f->html('</div>');
 201  
 202          
 203          $f->radio('type', $types2, $type, '', '', $attrs);
 204  
 205          if ( $this->settingsVars['clocktype'] == '<countdown>')
 206              {
 207              $f->html('<div id='.$this->paramName('countDiv').' style="display:block;">'); 
 208              }
 209          else
 210              {
 211              $f->html('<div id='.$this->paramName('countDiv').' style="display:none;">');
 212              }
 213           
 214          $f->html('Enter the event that will take place at the given time:');
 215          $f->text('event', $this->settingsVars['event'], 30  );
 216          
 217          $f->html('<br>');
 218          $f->date('date', $this->settingsVars['date'] );
 219          
 220          $hours = array( '0' => '12 Midnight', '1' => '1 AM', '2' => '2 AM', '3' => '3 AM', '4' => '4 AM', '5' => '5 AM', 
 221          '6' => '6 AM', '7' => '7 AM', '8'=>'8 AM', '9' => '9 AM', '10' => '10 AM', '11' => '11 AM', '12' => '12 Noon',
 222          '13' => '1 PM', '14' => '2 PM', '15' => '3 PM', '16' => '4 PM', '17' => '5 PM', '18' => '6 PM', '19' => '7 PM', 
 223          '20' => '8 PM', '21' => '9 PM', '22' => '10 PM', '23' => '11 PM');
 224          $f->dropdown('hours', $hours, @$this->params['hours'], '0');
 225          $f->html(':');
 226          $numbers = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', 
 227                            '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', 
 228                            '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', 
 229                            '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29',
 230                            '30' => '30', '31' => '31', '32' => '32', '33' => '33', '34' => '34', '35' => '35', '36' => '36',
 231                            '37' => '37', '38' => '38', '39' => '39', '40' => '40', '41' => '41', '42' => '42', '43' => '43',
 232                            '44' => '44', '45' => '45', '46' => '46', '47' => '47', '48' => '48', '49' => '49', '50' => '50',
 233                            '51' => '51', '52' => '52', '53' => '53', '54' => '54', '55' => '55', '56' => '56', '57' => '57',
 234                            '58' => '58', '59' => '59' );
 235         $f->dropdown('minutes', $numbers, @$this->params['minutes'], '0');
 236          $f->html('minutes:');
 237          $f->dropdown('seconds', $numbers, @$this->params['seconds'], '0');
 238          $f->html('seconds<br>Enter message to be displayed when the countdown time reaches zero:');
 239          
 240          $f->text('expiredmessage',$this->settingsVars['expiredmessage']);
 241          
 242          $f->html('</div>');
 243  
 244          $f->radio('type', $types3, $type, '', '<br>', $attrs);
 245  
 246          if ( $this->settingsVars['type'] != 'custom' )
 247              {
 248              $f->html('<div id='.$this->paramName('customDiv').' style="display:none;">'); 
 249              }
 250          else
 251              {
 252              $f->html('<div id='.$this->paramName('customDiv').' style="display:block;">');
 253              }
 254        
 255          $f->textarea('clocktype', $this->settingsVars['clocktype'], 5, 30, array('id' => $this->paramName('clocktype')));
 256          $f->html('<table><tr><td><br>');
 257          
 258          //each button calls a function to make sure it is inserted at the cursors current position
 259          $f->button('seconds', 'Current Seconds',
 260          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<seconds>\','.$this->paramName('clocktype').'.value,\''
 261          .$this->paramName('customstore').'\');'
 262          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 263                  'style' => 'width:160px'))  ;
 264          $f->html('<br>');
 265                                          
 266          $f->button('minutes', 'Current Minutes',
 267          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<minutes>\','.$this->paramName('clocktype').'.value,\''
 268          .$this->paramName('customstore').'\');'
 269          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 270                  'style' => 'width:160px'))  ;
 271          $f->html('<br>');
 272          
 273          $f->button('hournum', 'Current Hour(number)',
 274          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<hournum>\','.$this->paramName('clocktype').'.value,\''
 275          .$this->paramName('customstore').'\');'
 276          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 277                  'style' => 'width:160px'))  ;
 278          $f->html('<br>');
 279          
 280          $f->button('hourword', 'Current Hour(word)',
 281          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<hourword>\','.$this->paramName('clocktype').'.value,\''
 282          .$this->paramName('customstore').'\');'
 283          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 284                  'style' => 'width:160px'))  ;
 285          $f->html('<br></td><td><br>');
 286          
 287          $f->button('daynum', 'Current Day(number)',
 288          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<daynum>\','.$this->paramName('clocktype').'.value,\''
 289          .$this->paramName('customstore').'\');'
 290          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 291                  'style' => 'width:160px'))  ;
 292          $f->html('<br>');
 293          
 294          $f->button('dayword', 'Current Day(word)',
 295          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<dayword>\','.$this->paramName('clocktype').'.value,\''
 296          .$this->paramName('customstore').'\');'
 297          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 298                  'style' => 'width:160px'))  ;
 299          $f->html('<br>');
 300          
 301          $f->button('monthnum', 'Current Month(number)',
 302          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<monthnum>\','.$this->paramName('clocktype').'.value,\''
 303          .$this->paramName('customstore').'\');'
 304          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 305                  'style' => 'width:160px'))  ;
 306          $f->html('<br>');
 307          
 308          $f->button('monthword', 'Current Month(word)',
 309          'insertAtCursor(\''.$this->paramName('clocktype').'\',\'<monthword>\','.$this->paramName('clocktype').'.value,\''
 310          .$this->paramName('customstore').'\');'
 311          ."this.form.".$this->paramName('type')."[3].checked=true;", array('id' => $this->paramName('clocktype'),
 312                  'style' => 'width:160px'))  ;
 313          
 314          $f->html('</td></tr></table></div>');
 315          
 316          $f->endSection();
 317          $f->defaultButtons();
 318  
 319          return $f->get();
 320          }
 321          
 322      }
 323      
 324  ?>

title

Description

title

Description

title

Description

title

title

Body