home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / calendar / addedit.php next >
Encoding:
PHP Script  |  2004-01-29  |  7.4 KB  |  230 lines

  1. <?php /* CALENDAR $Id: addedit.php,v 1.32 2004/01/29 06:26:17 ajdonnison Exp $ */
  2. $event_id = intval( dPgetParam( $_GET, "event_id", 0 ) );
  3.  
  4. // check permissions
  5. if (!$canEdit) {
  6.     $AppUI->redirect( "m=public&a=access_denied" );
  7. }
  8.  
  9. // get the passed timestamp (today if none)
  10. $date = dPgetParam( $_GET, 'date', null );
  11.  
  12. // load the record data
  13. $obj = new CEvent();
  14.  
  15. if (!$obj->load( $event_id ) && $event_id) {
  16.     $AppUI->setMsg( 'Event' );
  17.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  18.     $AppUI->redirect();
  19. }
  20. // check only owner can edit
  21. if ($obj->event_owner != $AppUI->user_id && $event_id != 0) {
  22.     $AppUI->redirect( "m=public&a=access_denied" );
  23. }
  24.  
  25. // load the event types
  26. $types = dPgetSysVal( 'EventType' );
  27.  
  28. // setup the title block
  29. $titleBlock = new CTitleBlock( ($event_id ? "Edit Event" : "Add Event") , 'myevo-appointments.png', $m, "$m.$a" );
  30. $titleBlock->addCrumb( "?m=calendar", "month view" );
  31. if ($event_id) {
  32.     $titleBlock->addCrumb( "?m=calendar&a=view&event_id=$event_id", "view this event" );
  33. }
  34. $titleBlock->show();
  35.  
  36. // format dates
  37. $df = $AppUI->getPref('SHDATEFORMAT');
  38.  
  39. // pull projects
  40. $sql = "SELECT project_id, project_name FROM projects ORDER BY project_name";
  41. $all_projects = '(' . $AppUI->_('All') . ')';
  42. $projects = arrayMerge( array( 0 => $all_projects ), db_loadHashList( $sql ) );
  43.  
  44. if ($event_id) {
  45.     $start_date = intval( $obj->event_start_date ) ? new CDate( $obj->event_start_date ) : null;
  46.     $end_date = intval( $obj->event_end_date ) ? new CDate( $obj->event_end_date ) : $start_date;
  47. } else {
  48.     $start_date = new CDate( $date );
  49.     $start_date->setTime( 8,0,0 );
  50.     $end_date = new CDate( $date );
  51.     $end_date->setTime( 17,0,0 );
  52. }
  53.  
  54. $recurs =  array (
  55.     'Never',
  56.     'Hourly',
  57.     'Daily',
  58.     'Weekly',
  59.     'Bi-Weekly',
  60.     'Every Month',
  61.     'Quarterly',
  62.     'Every 6 months',
  63.     'Every Year'
  64. );
  65.  
  66. $remind = array (
  67.     "900" => '15 mins',
  68.     "1800" => '30 mins',
  69.     "3600" => '1 hour',
  70.     "7200" => '2 hours',
  71.     "14400" => '4 hours',
  72.     "28800" => '8 hours',
  73.     "56600" => '16 hours',
  74.     "86400" => '1 day',
  75.     "172800" => '2 days'
  76. );
  77.  
  78. // build array of times in 30 minute increments
  79. $times = array();
  80. $t = new CDate();
  81. $t->setTime( 0,0,0 );
  82. if (!defined('LOCALE_TIME_FORMAT'))
  83.   define('LOCALE_TIME_FORMAT', '%I:%M %p');
  84. for ($m=0; $m < 60; $m++) {
  85.     $times[$t->format( "%H%M%S" )] = $t->format( LOCALE_TIME_FORMAT );
  86.     $t->addSeconds( 1800 );
  87. }
  88. ?>
  89.  
  90. <script language="javascript">
  91. function submitIt(){
  92.     var form = document.editFrm;
  93.     if (form.event_title.value.length < 1) {
  94.         alert("Please enter a valid event title");
  95.         form.event_title.focus();
  96.     }
  97.     if (form.event_start_date.value.length < 1){
  98.         alert("Please enter a start date");
  99.         form.event_start_date.focus();
  100.     }
  101.     if (form.event_end_date.value.length < 1){
  102.         alert("Please enter an end date");
  103.         form.event_end_date.focus();
  104.     }
  105. /* FUNCTIONALITY NOT YET ENABLED
  106.     if (form.event_recurs.selectedIndex != 0 && isNaN(parseInt(form.event_times_recuring.value))){
  107.         alert("Please select how often you wish this event to recur.");
  108.         form.event_times_recuring.focus();
  109.     } else {
  110. */
  111.         form.submit();
  112. /*
  113.     }
  114. */
  115. }
  116.  
  117. var calendarField = '';
  118.  
  119. function popCalendar( field ){
  120.     calendarField = field;
  121.     idate = eval( 'document.editFrm.event_' + field + '.value' );
  122.     window.open( 'index.php?m=public&a=calendar&dialog=1&callback=setCalendar&date=' + idate, 'calwin', 'top=250,left=250,width=250, height=220, scollbars=false' );
  123. }
  124.  
  125. /**
  126.  *    @param string Input date in the format YYYYMMDD
  127.  *    @param string Formatted date
  128.  */
  129. function setCalendar( idate, fdate ) {
  130.     fld_date = eval( 'document.editFrm.event_' + calendarField );
  131.     fld_fdate = eval( 'document.editFrm.' + calendarField );
  132.     fld_date.value = idate;
  133.     fld_fdate.value = fdate;
  134. }
  135. </script>
  136.  
  137. <table cellspacing="1" cellpadding="2" border="0" width="100%" class="std">
  138. <form name="editFrm" action="?m=calendar" method="post">
  139.     <input type="hidden" name="dosql" value="do_event_aed" />
  140.     <input type="hidden" name="event_id" value="<?php echo $event_id;?>" />
  141.     <input type="hidden" name="event_project" value="0" />
  142.  
  143. <tr>
  144.     <td width="33%" align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Event Title' );?>:</td>
  145.     <td width="20%">
  146.         <input type="text" class="text" size="25" name="event_title" value="<?php echo @$obj->event_title;?>" maxlength="255">
  147.     </td>
  148. </tr>
  149.  
  150. <tr>
  151.     <td align="right"><?php echo $AppUI->_('Type');?>:</td>
  152.     <td>
  153. <?php
  154.     echo arraySelect( $types, 'event_type', 'size="1" class="text"', @$obj->event_type, true );
  155. ?>
  156.     </td>
  157. </tr>
  158.     
  159. <tr>
  160.     <td align="right"><?php echo $AppUI->_('Project');?>:</td>
  161.     <td>
  162. <?php
  163.     echo arraySelect( $projects, 'event_project', 'size="1" class="text"', @$obj->event_project );
  164. ?>
  165.     </td>
  166. </tr>    
  167.  
  168.  
  169. <tr>
  170.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Private Entry' );?>:</td>
  171.     <td>
  172.         <input type="checkbox" value="1" name="event_private" <?php echo (@$obj->event_private ? 'checked' : '');?>>
  173.     </td>
  174. </tr>
  175. <tr>
  176.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Start Date' );?>:</td>
  177.     <td nowrap="nowrap">
  178.         <input type="hidden" name="event_start_date" value="<?php echo $start_date ? $start_date->format( FMT_TIMESTAMP_DATE ) : '';?>">
  179.         <input type="text" name="start_date" value="<?php echo $start_date ? $start_date->format( $df ) : '';?>" class="text" disabled="disabled">
  180.         <a href="#" onClick="popCalendar('start_date')">
  181.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  182.         </a>
  183.     </td>
  184.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Time' );?>:</td>
  185.     <td><?php echo arraySelect( $times, 'start_time', 'size="1" class="text"', $start_date->format( "%H%M%S" ) ); ?></td>
  186. </tr>
  187.  
  188. <tr>
  189.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'End Date' );?>:</td>
  190.     <td nowrap="nowrap">
  191.         <input type="hidden" name="event_end_date" value="<?php echo $end_date ? $end_date->format( FMT_TIMESTAMP_DATE ) : '';?>">
  192.         <input type="text" name="end_date" value="<?php echo $end_date ? $end_date->format( $df ) : '';?>" class="text" disabled="disabled">
  193.         <a href="#" onClick="popCalendar('end_date')">
  194.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  195.         </a>
  196.     </td>
  197.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Time' );?>:</td>
  198.     <td><?php echo arraySelect( $times, 'end_time', 'size="1" class="text"', $end_date->format( "%H%M%S" ) ); ?></td>
  199. </tr>
  200. <tr>
  201.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Recurs' );?>:</td>
  202.     <td><?php echo arraySelect( $recurs, 'event_recurs', 'size="1" class="text"', $obj->event_recurs, true ); ?></td>
  203.     <td align="right">x</td>
  204.     <td>
  205.         <input type="text"  name="event_times_recuring" value="<?php echo @$obj->event_times_recuring;?>" maxlength="2" size=3> <?php echo $AppUI->_( 'times' );?>
  206.     </td>
  207. </tr>
  208. <?php /* FUNCTIONALITY NOT YET ENABLED ?>
  209. <tr>
  210.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Remind Me' );?>:</td>
  211.     <td><?php echo arraySelect( $remind, 'event_remind', 'size="1" class="text"', $obj['event_remind'] ); ?> <?php echo $AppUI->_( 'in advance' );?></td>
  212. </tr>
  213. <?php */ ?>
  214. <tr>
  215.     <td valign="top" align="right"><?php echo $AppUI->_( 'Description' );?></td>
  216.     <td align="left" colspan="3">
  217.         <textarea class="textarea" name="event_description" rows="5" cols="45"><?php echo @$obj->event_description;?></textarea></td>
  218.     </td>
  219. </tr>
  220. <tr>
  221.     <td colspan="2">
  222.         <input type="button" value="<?php echo $AppUI->_( 'back' );?>" class="button" onclick="javascript:history.back();">
  223.     </td>
  224.     <td align="right" colspan="2">
  225.         <input type="button" value="<?php echo $AppUI->_( 'submit' );?>" class="button" onClick="submitIt()">
  226.     </td>
  227. </tr>
  228. </form>
  229. </table>
  230.