[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/calendar/ -> addedit.php (source)

   1  <?php /* $Id: addedit.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/calendar/addedit.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  global $AppUI, $cal_sdf;
   6  $AppUI->loadCalendarJS();
   7  
   8  $event_id = intval(w2PgetParam($_GET, 'event_id', 0));
   9  $is_clash = isset($_SESSION['event_is_clash']) ? $_SESSION['event_is_clash'] : false;
  10  
  11  $perms = &$AppUI->acl();
  12  $canAuthor = $perms->checkModule('calendar', 'add');
  13  $canEdit = $perms->checkModuleItem('calendar', 'edit', $event_id);
  14  
  15  // check permissions
  16  if (!$canAuthor && !$event_id) {
  17      $AppUI->redirect('m=public&a=access_denied');
  18  }
  19  
  20  if (!$canEdit && $event_id) {
  21      $AppUI->redirect('m=public&a=access_denied');
  22  }
  23  
  24  // get the passed timestamp (today if none)
  25  $date = w2PgetParam($_GET, 'date', null);
  26  
  27  // load the record data
  28  $obj = new CEvent();
  29  
  30  if ($is_clash) {
  31      $obj->bind($_SESSION['add_event_post']);
  32  } else
  33      if (!$obj->load($event_id) && $event_id) {
  34          $AppUI->setMsg('Event');
  35          $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
  36          $AppUI->redirect();
  37      }
  38  
  39  // load the event types
  40  $types = w2PgetSysVal('EventType');
  41  
  42  // Load the users
  43  $users = $perms->getPermittedUsers('calendar');
  44  
  45  // Load the assignees
  46  $assigned = array();
  47  if ($is_clash) {
  48      $assignee_list = $_SESSION['add_event_attendees'];
  49      if (isset($assignee_list) && $assignee_list) {
  50          $q = new DBQuery;
  51          $q->addTable('users', 'u');
  52          $q->addTable('contacts', 'con');
  53          $q->addQuery('user_id, CONCAT_WS(\' \' , contact_first_name, contact_last_name)');
  54          $q->addWhere('user_id IN ('.$assignee_list.')');
  55          $q->addWhere('user_contact = contact_id');
  56          $assigned = $q->loadHashList();
  57      } else {
  58      }
  59  } else
  60      if ($event_id == 0) {
  61          $assigned[$AppUI->user_id] = $AppUI->user_first_name . ' ' . $AppUI->user_last_name;
  62      } else {
  63          $assigned = $obj->getAssigned();
  64      }
  65      // Now that we have loaded the possible replacement event,  remove the stored
  66      // details, NOTE: This could cause using a back button to make things break,
  67      // but that is the least of our problems.
  68      if ($is_clash) {
  69          unset($_SESSION['add_event_post']);
  70          unset($_SESSION['add_event_attendees']);
  71          unset($_SESSION['add_event_mail']);
  72          unset($_SESSION['add_event_clash']);
  73          unset($_SESSION['event_is_clash']);
  74      }
  75  if ($_GET['event_project']) {
  76      $obj->event_project = w2PgetParam($_GET, 'event_project', 0);
  77  }
  78  
  79  //check if the user has view permission over the project
  80  if ($obj->event_project && !$perms->checkModuleItem('projects', 'view', $obj->event_project)) {
  81      $AppUI->redirect('m=public&a=access_denied');
  82  }
  83  
  84  // setup the title block
  85  $titleBlock = new CTitleBlock(($event_id ? 'Edit Event' : 'Add Event'), 'myevo-appointments.png', $m, $m . '.' . $a);
  86  $titleBlock->addCrumb('?m=calendar', 'month view');
  87  if ($event_id) {
  88      $titleBlock->addCrumb('?m=calendar&amp;a=view&event_id=' . $event_id, 'view this event');
  89  }
  90  $titleBlock->show();
  91  
  92  // format dates
  93  $df = $AppUI->getPref('SHDATEFORMAT');
  94  
  95  // pull projects
  96  require_once ($AppUI->getModuleClass('projects'));
  97  $q = &new DBQuery;
  98  $q->addTable('projects', 'pr');
  99  $q->addQuery('pr.project_id, pr.project_name');
 100  
 101  $prj = &new CProject;
 102  $allowedProjects = $prj->getAllowedSQL($AppUI->user_id);
 103  
 104  if (count($allowedProjects)) {
 105      $prj->setAllowedSQL($AppUI->user_id, $q, null, 'pr');
 106  }
 107  $q->addOrder('project_name');
 108  
 109  $all_projects = '(' . $AppUI->_('All', UI_OUTPUT_RAW) . ')';
 110  $projects = arrayMerge(array(0 => $all_projects), $q->loadHashList());
 111  
 112  if ($event_id || $is_clash) {
 113      $start_date = intval($obj->event_start_date) ? new CDate($obj->event_start_date) : null;
 114      $end_date = intval($obj->event_end_date) ? new CDate($obj->event_end_date) : $start_date;
 115  } else {
 116      $start_date = new CDate($date);
 117      $start_date->setTime(8, 0, 0);
 118      $end_date = new CDate($date);
 119      $end_date->setTime(17, 0, 0);
 120  }
 121  
 122  $inc = intval(w2PgetConfig('cal_day_increment')) ? intval(w2PgetConfig('cal_day_increment')) : 30;
 123  if (!$event_id && !$is_clash) {
 124  
 125      $seldate = new CDate($date);
 126      // If date is today, set start time to now + inc
 127      if ($date == date('Ymd')) {
 128          $h = date('H');
 129          // an interval after now.
 130          $min = intval(date('i') / $inc) + 1;
 131          $min *= $inc;
 132          if ($min > 60) {
 133              $min = 0;
 134              $h++;
 135          }
 136      }
 137      if ($h && $h < w2PgetConfig('cal_day_end')) {
 138          $seldate->setTime($h, $min, 0);
 139          $obj->event_start_date = $seldate->format(FMT_TIMESTAMP);
 140          $seldate->addSeconds($inc * 60);
 141          $obj->event_end_date = $seldate->format(FMT_TIMESTAMP);
 142      } else {
 143          $seldate->setTime(w2PgetConfig('cal_day_start'), 0, 0);
 144          $obj->event_start_date = $seldate->format(FMT_TIMESTAMP);
 145          $seldate->setTime(w2PgetConfig('cal_day_end'), 0, 0);
 146          $obj->event_end_date = $seldate->format(FMT_TIMESTAMP);
 147      }
 148  }
 149  
 150  $recurs = array('Never', 'Hourly', 'Daily', 'Weekly', 'Bi-Weekly', 'Every Month', 'Quarterly', 'Every 6 months', 'Every Year');
 151  
 152  $remind = array('900' => '15 mins', '1800' => '30 mins', '3600' => '1 hour', '7200' => '2 hours', '14400' => '4 hours', '28800' => '8 hours', '56600' => '16 hours', '86400' => '1 day', '172800' => '2 days');
 153  
 154  // build array of times in 30 minute increments
 155  $times = array();
 156  $t = new CDate();
 157  $t->setTime(0, 0, 0);
 158  //$m clashes with global $m (module)
 159  for ($minutes = 0; $minutes < ((24 * 60) / $inc); $minutes++) {
 160      $times[$t->format('%H%M%S')] = $t->format($AppUI->getPref('TIMEFORMAT'));
 161      $t->addSeconds($inc * 60);
 162  }
 163  ?>
 164  <script language="javascript">
 165  function submitIt(){
 166      var form = document.editFrm;
 167      if (form.event_title.value.length < 1) {
 168          alert('<?php echo $AppUI->_('Please enter a valid event title', UI_OUTPUT_JS); ?>');
 169          form.event_title.focus();
 170          return;
 171      }
 172      if (form.event_start_date.value.length < 1){
 173          alert('<?php echo $AppUI->_('Please enter a start date', UI_OUTPUT_JS); ?>');
 174          form.event_start_date.focus();
 175          return;
 176      }
 177      if (form.event_end_date.value.length < 1){
 178          alert('<?php echo $AppUI->_('Please enter an end date', UI_OUTPUT_JS); ?>');
 179          form.event_end_date.focus();
 180          return;
 181      }
 182      if ( (!(form.event_times_recuring.value>0)) 
 183          && (form.event_recurs[0].selected!=true) ) {
 184          alert("<?php echo $AppUI->_('Please enter number of recurrences', UI_OUTPUT_JS); ?>");
 185          form.event_times_recuring.value=1;
 186          form.event_times_recuring.focus();
 187          return;
 188      } 
 189      // Ensure that the assigned values are selected before submitting.
 190      var assigned = form.assigned;
 191      var len = assigned.length;
 192      var users = form.event_assigned;
 193      users.value = '';
 194      for (var i = 0; i < len; i++) {
 195          if (i) {
 196              users.value += ',';
 197          }
 198          users.value += assigned.options[i].value;
 199      }
 200      form.submit();
 201  }
 202  
 203  function setDate( frm_name, f_date ) {
 204      fld_date = eval( 'document.' + frm_name + '.' + f_date );
 205      fld_real_date = eval( 'document.' + frm_name + '.' + 'event_' + f_date );
 206      if (fld_date.value.length>0) {
 207        if ((parseDate(fld_date.value))==null) {
 208              alert('The Date/Time you typed does not match your prefered format, please retype.');
 209              fld_real_date.value = '';
 210              fld_date.style.backgroundColor = 'red';
 211          } else {
 212              fld_real_date.value = formatDate(parseDate(fld_date.value), 'yyyyMMdd');
 213              fld_date.value = formatDate(parseDate(fld_date.value), "<?php echo $cal_sdf ?>");
 214              fld_date.style.backgroundColor = '';
 215            }
 216      } else {
 217            fld_real_date.value = '';
 218      }
 219  }
 220  
 221  function addUser() {
 222      var form = document.editFrm;
 223      var fl = form.resources.length -1;
 224      var au = form.assigned.length -1;
 225      //gets value of percentage assignment of selected resource
 226  
 227      var users = 'x';
 228  
 229      //build array of assiged users
 230      for (au; au > -1; au--) {
 231          users = users + ',' + form.assigned.options[au].value + ','
 232      }
 233  
 234      //Pull selected resources and add them to list
 235      for (fl; fl > -1; fl--) {
 236          if (form.resources.options[fl].selected && users.indexOf( ',' + form.resources.options[fl].value + ',' ) == -1) {
 237              t = form.assigned.length
 238              opt = new Option( form.resources.options[fl].text, form.resources.options[fl].value);
 239              form.assigned.options[t] = opt
 240          }
 241      }
 242  
 243  }
 244  
 245  function removeUser() {
 246      var form = document.editFrm;
 247      fl = form.assigned.length -1;
 248      for (fl; fl > -1; fl--) {
 249          if (form.assigned.options[fl].selected) {
 250              //remove from hperc_assign
 251              var selValue = form.assigned.options[fl].value;            
 252              var re = ".*("+selValue+"=[0-9]*;).*";
 253              form.assigned.options[fl] = null;
 254          }
 255      }
 256  }
 257  </script>
 258  <table border="0" cellpadding="4" cellspacing="0" width="100%" class="std">
 259  <tr>
 260      <td colspan="2">
 261          <table width="100%" border="0" cellpadding="1" cellspacing="1">
 262          <form name="editFrm" action="?m=calendar" method="post">
 263              <input type="hidden" name="dosql" value="do_event_aed" />
 264              <input type="hidden" name="event_id" value="<?php echo $event_id; ?>" />
 265              <input type="hidden" name="event_assigned" value="" />
 266          <tr>    
 267              <td width="20%" align="right" nowrap="nowrap"><?php echo $AppUI->_('Event Title'); ?>:</td>
 268              <td width="20%">
 269                  <input type="text" class="text" size="25" name="event_title" value="<?php echo $obj->event_title; ?>" maxlength="255" />
 270              </td>
 271              <td align="left" rowspan="4" valign="top" colspan="2" width="40%">
 272              <?php echo $AppUI->_('Description'); ?> :<br/>
 273                  <textarea class="textarea" name="event_description" rows="5" cols="45"><?php echo $obj->event_description; ?></textarea></td>
 274              </td>
 275          </tr>
 276          <tr>
 277              <td align="right"><?php echo $AppUI->_('Type'); ?>:</td>
 278              <td>
 279          <?php
 280  echo arraySelect($types, 'event_type', 'size="1" class="text"', $obj->event_type, true);
 281  ?>
 282              </td>
 283          </tr>
 284              
 285          <tr>
 286              <td align="right"><?php echo $AppUI->_('Project'); ?>:</td>
 287              <td>
 288          <?php
 289  echo arraySelect($projects, 'event_project', 'size="1" class="text"', ($obj->event_project ? $obj->event_project : 0));
 290  ?>
 291              </td>
 292          </tr>
 293          
 294          
 295          <tr>
 296              <td align="right" nowrap="nowrap"><label for="event_private"><?php echo $AppUI->_('Private Entry'); ?>:</label></td>
 297              <td>
 298                  <input type="checkbox" value="1" name="event_private" id="event_private" <?php echo ($obj->event_private ? 'checked="checked"' : ''); ?> />
 299              </td>
 300          </tr>
 301          <tr>
 302              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Start Date'); ?>:</td>
 303              <td nowrap="nowrap">
 304                  <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo $start_date ? $start_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" />
 305                  <input type="text" name="start_date" id="start_date" onchange="setDate('editFrm', 'start_date');" value="<?php echo $start_date ? $start_date->format($df) : ''; ?>" class="text" />
 306                  <a href="javascript: void(0);" onclick="return showCalendar('start_date', '<?php echo $df ?>', 'editFrm', null, true)">
 307                      <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" />
 308                  </a>
 309              </td>
 310              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Time'); ?>:</td>
 311              <td><?php echo arraySelect($times, 'start_time', 'size="1" class="text"', $start_date->format('%H%M%S')); ?></td>
 312          </tr>
 313          
 314          <tr>
 315              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('End Date'); ?>:</td>
 316              <td nowrap="nowrap">
 317                  <input type="hidden" name="event_end_date" id="event_end_date" value="<?php echo $end_date ? $end_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" />
 318                  <input type="text" name="end_date" id="end_date" onchange="setDate('editFrm', 'end_date');" value="<?php echo $end_date ? $end_date->format($df) : ''; ?>" class="text" />
 319                  <a href="javascript: void(0);" onclick="return showCalendar('end_date', '<?php echo $df ?>', 'editFrm', null, true)">
 320                      <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" />
 321                  </a>
 322              </td>
 323              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Time'); ?>:</td>
 324              <td><?php echo arraySelect($times, 'end_time', 'size="1" class="text"', $end_date->format('%H%M%S')); ?></td>
 325          </tr>
 326          <tr>
 327              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Recurs'); ?>:</td>
 328              <td><?php echo arraySelect($recurs, 'event_recurs', 'size="1" class="text"', $obj->event_recurs, true); ?></td>
 329              <td align="right">x</td>
 330              <td>
 331                  <input type="text" class="text" name="event_times_recuring" value="<?php echo ((isset($obj->event_times_recuring)) ? ($obj->event_times_recuring) : '1'); ?>" maxlength="2" size="3" /> <?php echo $AppUI->_('times'); ?>
 332              </td>
 333          </tr>
 334          <?php /* FUNCTIONALITY NOT YET ENABLED ?>
 335  <tr>
 336  <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Remind Me' );?>:</td>
 337  <td><?php echo arraySelect( $remind, 'event_remind', 'size="1" class="text"', $obj['event_remind'] ); ?> <?php echo $AppUI->_( 'in advance' );?></td>
 338  </tr>
 339  <?php */ ?>
 340          
 341          <tr>
 342              <td align="right"><?php echo $AppUI->_('Resources'); ?>:</td>
 343              <td></td>
 344              <td align="left"><?php echo $AppUI->_('Invited to Event'); ?>:</td>
 345              <td></td>
 346          </tr>
 347          <tr>
 348              <td width="50%" colspan="2" align="right">
 349              <?php echo arraySelect($users, 'resources', 'style="width:220px" size="10" class="text" multiple="multiple" ', null); ?>
 350              </td>
 351              <td width="50%" colspan="2" align="left">
 352              <?php echo arraySelect($assigned, 'assigned', 'style="width:220px" size="10" class="text" multiple="multiple" ', null); ?>
 353              </td>
 354          </tr>
 355          <tr>
 356              <td width="50%" colspan="2" align="right">
 357                  <input type="button" class="button" value="&gt;" onclick="addUser()" />
 358              </td>
 359              <td width="50%" colspan="2" align="left">
 360                  <input type="button" class="button" value="&lt;" onclick="removeUser()" />
 361              </td>
 362          </tr>
 363          <tr>
 364              <td align="right" nowrap="nowrap"><label for="event_cwd"><?php echo $AppUI->_('Show only on Working Days'); ?>:</label></td>
 365              <td>
 366                  <input type="checkbox" value="1" name="event_cwd" id="event_cwd" <?php echo ($obj->event_cwd ? 'checked="checked"' : ''); ?> />
 367              </td>
 368              <td align="right"><label for="mail_invited"><?php echo $AppUI->_('Mail Attendees?'); ?></label> <input type="checkbox" name="mail_invited" id="mail_invited" checked="checked" /></td>
 369          </tr>
 370          <tr>
 371              <td colspan="2" align="right">
 372                      <?php
 373  // $m does not equal 'calendar' here???
 374  require_once $AppUI->getSystemClass('CustomFields');
 375  $custom_fields = new CustomFields('calendar', 'addedit', $obj->event_id, 'edit');
 376  $custom_fields->printHTML();
 377  ?>
 378              </td>
 379          <tr>
 380              <td colspan="2">
 381                  <input type="button" value="<?php echo $AppUI->_('back'); ?>" class="button" onclick="javascript:history.back();" />
 382              </td>
 383              <td align="right" colspan="2">
 384                  <input type="button" value="<?php echo $AppUI->_('submit'); ?>" class="button" onclick="submitIt()" />
 385              </td>
 386          </tr>
 387          </form>
 388          </table>
 389      </td>
 390  </tr>
 391  </table>


Generated: Wed Jan 7 03:00:01 2009 Cross-referenced by PHPXref 0.7