Example #1
0
function show_add_form($id = '')
{
    global $MonthsLong;
    $htmlHeadXtra[] = to_javascript();
    // the default values for the forms
    if ($_GET['originalresource'] !== 'no') {
        $day = date('d');
        $month = date('m');
        $year = date('Y');
        $hours = 9;
        $minutes = '00';
        $end_day = date('d');
        $end_month = date('m');
        $end_year = date('Y');
        $end_hours = 17;
        $end_minutes = '00';
        $repeat = false;
    } else {
        // we are coming from the resource linker so there might already have been some information in the form.
        // When we clicked on the button to add resources we stored every form information into a session and now we
        // are doing the opposite thing: getting the information out of the session and putting it into variables to
        // display it in the forms.
        $form_elements = $_SESSION['formelements'];
        $day = $form_elements['day'];
        $month = $form_elements['month'];
        $year = $form_elements['year'];
        $hours = $form_elements['hour'];
        $minutes = $form_elements['minutes'];
        $end_day = $form_elements['end_day'];
        $end_month = $form_elements['end_month'];
        $end_year = $form_elements['end_year'];
        $end_hours = $form_elements['end_hours'];
        $end_minutes = $form_elements['end_minutes'];
        $title = $form_elements['title'];
        $content = $form_elements['content'];
        $id = $form_elements['id'];
        $to = $form_elements['to'];
        $repeat = $form_elements['repeat'];
    }
    //	switching the send to all/send to groups/send to users
    if ($_POST['To']) {
        $day = $_POST['fday'];
        $month = $_POST['fmonth'];
        $year = $_POST['fyear'];
        $hours = $_POST['fhour'];
        $minutes = $_POST['fminute'];
        $end_day = $_POST['end_fday'];
        $end_month = $_POST['end_fmonth'];
        $end_year = $_POST['end_fyear'];
        $end_hours = $_POST['end_fhour'];
        $end_minutes = $_POST['end_fminute'];
        $title = $_POST['title'];
        $content = $_POST['content'];
        // the invisible fields
        $action = $_POST['action'];
        $id = $_POST['id'];
        $repeat = !empty($_POST['repeat']) ? true : false;
    }
    // if the id is set then we are editing an agenda item
    if (is_int($id)) {
        //echo "before get_agenda_item".$_SESSION['allow_individual_calendar'];
        $item_2_edit = get_agenda_item($id);
        $title = $item_2_edit['title'];
        $content = $item_2_edit['content'];
        // start date
        $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']);
        // start date
        list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
        list($year, $month, $day) = explode("-", $datepart);
        list($hours, $minutes, $seconds) = explode(":", $timepart);
        // end date
        $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']);
        list($datepart, $timepart) = split(" ", $item_2_edit['end_date']);
        list($end_year, $end_month, $end_day) = explode("-", $datepart);
        list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
        // attachments
        //edit_added_resources("Agenda", $id);
        $to = $item_2_edit['to'];
        //echo "<br />after get_agenda_item".$_SESSION['allow_individual_calendar'];
    }
    $content = stripslashes($content);
    $title = stripslashes($title);
    // we start a completely new item, we do not come from the resource linker
    if ($_GET['originalresource'] !== "no" and $_GET['action'] == "add") {
        $_SESSION["formelements"] = null;
    }
    ?>

<!-- START OF THE FORM  -->
<form enctype="multipart/form-data"  action="<?php 
    echo api_get_self() . '?origin=' . Security::remove_XSS($_GET['origin']) . '&amp;action=' . Security::remove_XSS($_GET['action']);
    ?>
" method="post" name="new_calendar_item">
<input type="hidden" name="id" value="<?php 
    if (isset($id)) {
        echo $id;
    }
    ?>
" />
<input type="hidden" name="action" value="<?php 
    if (isset($_GET['action'])) {
        echo Security::remove_XSS($_GET['action']);
    }
    ?>
" />
<input type="hidden" name="sort" value="asc" />
<input type="hidden" name="submit_event" value="ok" />
<?php 
    echo '<legend>';
    echo (isset($id) and $id != '') ? get_lang('ModifyCalendarItem') : get_lang("AddCalendarItem");
    echo '<legend>';
    ?>
<table border="0" cellpadding="5" cellspacing="0" width="80%" id="newedit_form">
	<!-- START date and time -->
<tr>
<div>
<table border="0" width="100%">
				<tr><td colspan="4">
					<div id="err_date" style="display:none;color:red"></div>
					<div id="err_start_date" style="display:none;color:red"></div>
				</td></tr>
				<td width="10%">
					<!-- date: 1 -> 31 -->
					<nobr><?php 
    echo get_lang('StartDate') . ": ";
    ?>
</nobr>
				</td>
				<td width="35%">
					<select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
							<?php 
    // small loop for filling all the dates
    // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
    foreach (range(1, 31) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        // the current day is indicated with [] around the date
        if ($value == $day) {
            echo " <option value=\"" . $value . "\" selected> " . $i . " </option>";
        } else {
            echo "<option value=\"{$value}\">{$i}</option>";
        }
    }
    ?>
					</select>
					<!-- month: january -> december -->
					<select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
					<?php 
    for ($i = 1; $i <= 12; $i++) {
        // values have to have double digits
        if ($i <= 9) {
            $value = "0" . $i;
        } else {
            $value = $i;
        }
        if ($value == $month) {
            echo " <option value=\"" . $value . "\" selected>" . $MonthsLong[$i - 1] . "</option>\n";
        } else {
            echo " <option value=\"" . $value . "\">" . $MonthsLong[$i - 1] . "</option>\n";
        }
    }
    ?>
					</select>
					<select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
										<option value="<?php 
    echo $year - 1;
    ?>
"><?php 
    echo $year - 1;
    ?>
</option>
											<option value="<?php 
    echo $year;
    ?>
" selected="selected"><?php 
    echo $year;
    ?>
</option>
											<?php 
    echo "\n";
    for ($i = 1; $i <= 5; $i++) {
        $value = $year + $i;
        echo "<option value=\"{$value}\">{$value}</option>\n";
    }
    ?>
					</select>
					<a href="javascript:openCalendar('new_calendar_item','f')"><?php 
    Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;'));
    ?>
</a>
					</td>
					<td width="10%">
						<nobr><?php 
    echo get_lang('StartTime') . ": \n";
    ?>
</nobr>
					</td>
					<td>
						<select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
							<!-- <option value="--">--</option> -->
							<?php 
    echo "\n";
    foreach (range(0, 23) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        // the current hour is indicated with [] around the hour
        if ($hours == $value) {
            echo "<option value=\"" . $value . "\" selected> " . $value . " </option>\n";
        } else {
            echo "<option value=\"{$value}\">{$value}</option>\n";
        }
    }
    ?>
						</select>

						<select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
							<!-- <option value="<?php 
    echo $minutes;
    ?>
"><?php 
    echo $minutes;
    ?>
</option> -->
							<!-- <option value="--">--</option> -->
							<?php 
    foreach (range(0, 59) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        if ($minutes == $value) {
            echo "<option value=\"" . $value . "\" selected> " . $value . " </option>";
        } else {
            echo "<option value=\"{$value}\">{$value}</option>";
        }
    }
    ?>
						</select>
					</td>

</div>
</tr>
			<!-- END date and time -->
<tr>
<div>
					<tr><td colspan="4"><div id="err_end_date" style="display:none;color:red"></div></td></tr>
					<td >
							<!-- date: 1 -> 31 -->
							<nobr><?php 
    echo get_lang('EndDate') . ": ";
    ?>
</nobr>
					</td>
					<td  >
						<select name="end_fday">
							<?php 
    // small loop for filling all the dates
    // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
    echo "\n";
    foreach (range(1, 31) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        // the current day is indicated with [] around the date
        if ($value == $end_day) {
            echo " <option value=\"" . $value . "\" selected> " . $i . " </option>\n";
        } else {
            echo " <option value=\"" . $value . "\">" . $i . "</option>\n";
        }
    }
    ?>
						</select>
							<!-- month: january -> december -->
						<select name="end_fmonth">
                            <?php 
    echo "\n";
    foreach (range(1, 12) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        if ($value == $end_month) {
            echo " <option value=\"" . $value . "\" selected>" . $MonthsLong[$i - 1] . "</option>\n";
        } else {
            echo " <option value=\"" . $value . "\">" . $MonthsLong[$i - 1] . "</option>\n";
        }
    }
    ?>
						</select>
						<select name="end_fyear">
                            <option value="<?php 
    echo $end_year - 1;
    ?>
"><?php 
    echo $end_year - 1;
    ?>
</option>
                            <option value="<?php 
    echo $end_year;
    ?>
" selected> <?php 
    echo $end_year;
    ?>
 </option>
                            <?php 
    echo "\n";
    for ($i = 1; $i <= 5; $i++) {
        $value = $end_year + $i;
        echo "<option value=\"{$value}\">{$value}</option>\n";
    }
    ?>
						</select>
						<a href="javascript:openCalendar('new_calendar_item', 'end_f')"><?php 
    Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;'));
    ?>
</a>
					</td>
					<td >
						<nobr><?php 
    echo get_lang('EndTime') . ": \n";
    ?>
</nobr>
					</td>
					<td >
						<select name="end_fhour">
							<!-- <option value="--">--</option> -->
							<?php 
    echo "\n";
    foreach (range(0, 23) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        // the current hour is indicated with [] around the hour
        if ($end_hours == $value) {
            echo "<option value=\"" . $value . "\" selected> " . $value . " </option>\n";
        } else {
            echo "<option value=\"" . $value . "\"> " . $value . " </option>\n";
        }
    }
    ?>
						</select>

						<select name="end_fminute">
							<!-- <option value="<?php 
    echo $end_minutes;
    ?>
"><?php 
    echo $end_minutes;
    ?>
</option> -->
							<!-- <option value="--">--</option> -->
							<?php 
    foreach (range(0, 59) as $i) {
        // values have to have double digits
        $value = $i <= 9 ? '0' . $i : $i;
        if ($minutes == $value) {
            echo "<option value=\"" . $value . "\" selected> " . $value . " </option>";
        } else {
            echo "<option value=\"{$value}\">{$value}</option>";
        }
    }
    ?>
						</select>
						<br>
				</td>
</div>
</tr>
<tr><td colspan="4">
<hr noshade="noshade" color="#cccccc" />
	<div id="err_title" style="display:none;color:red"></div>
</td></tr>
<tr class="subtitle">
		<td colspan="4" valign="top"><?php 
    echo get_lang('ItemTitle');
    ?>
 :
			<!--<div style='margin-left: 80px'><textarea name="title" cols="50" rows="2" wrap="virtual" style="vertical-align:top; width:75%; height:50px;"><?php 
    if (isset($title)) {
        echo $title;
    }
    ?>
</textarea></div>-->
			<input type="text" size="60" name="title" value="<?php 
    if (isset($title)) {
        echo $title;
    }
    ?>
" />
		</td>
	</tr>

	<tr>
		<td colspan="4">

			<?php 
    require_once api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php";
    $oFCKeditor = new FCKeditor('content');
    $oFCKeditor->ToolbarSet = 'GlobalAgenda';
    $oFCKeditor->Width = '100%';
    $oFCKeditor->Height = '175';
    $oFCKeditor->Value = $content;
    $return = $oFCKeditor->CreateHtml();
    echo $return;
    ?>
		</td>
	</tr>
	<!--<?php 
    /* ADDED BY UGENT, Patrick Cool, march 2004 */
    ?>
	<tr>
		<td colspan="4">
	    <?php 
    //onclick="selectAll(this.form.elements[6],true)"
    //				show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
    ?>
		</td>
	</tr>-->
	<?php 
    //if ($_SESSION['addedresource'])
    echo "<tr>\n";
    echo "<td colspan=\"4\">\n";
    //echo display_resources(0);//--------------------------------------------------------
    $test = $_SESSION['addedresource'];
    echo "</td>\n</tr>\n";
    /* END ADDED BY UGENT, Patrick Cool, march 2004 */
    if (empty($id)) {
        ?>

    <tr>
      <td colspan="4" />
    </tr>
    <?php 
    }
    //only show repeat fields if adding, not if editing
    ?>
	<tr>
		<td colspan="4">
		<?php 
    if ($_GET['action'] == 'edit') {
        $class = 'save';
        $text = get_lang('ModifyEvent');
    } else {
        $class = 'add';
        $text = get_lang('AddEvent');
    }
    ?>
		<button type="button" class="add" value="<?php 
    echo get_lang('Ok');
    ?>
" onclick="validate_date()" ><?php 
    echo $text;
    ?>
</button>

		</td>
	</tr>
</table>
</form>
<?php 
}
     //$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent
     $vevent->setProperty('description', api_convert_encoding($ai['text'], 'UTF-8', $charset));
     //$vevent->setProperty( 'comment', 'This is a comment' );
     $user = api_get_user_info($ai['user']);
     $vevent->setProperty('organizer', $user['mail']);
     $vevent->setProperty('attendee', $user['mail']);
     //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks
     $ical->setConfig('filename', $y . $m . $d . $h . $M . $s . '-' . rand(1, 1000) . '.ics');
     $ical->setComponent($vevent);
     // add event to calendar
     $ical->returnCalendar();
     break;
 case 'course':
     $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
     require_once api_get_path(SYS_CODE_PATH) . 'admin/calendar.lib.php';
     $ai = get_agenda_item($_GET['id']);
     $vevent->setProperty('summary', api_convert_encoding($ai['title'], 'UTF-8', $charset));
     if (empty($ai['start_date'])) {
         header('location:' . $_SERVER['REFERER_URI']);
     }
     list($y, $m, $d, $h, $M, $s) = preg_split('/[\\s:-]/', $ai['start_date']);
     $vevent->setProperty('dtstart', array('year' => $y, 'month' => $m, 'day' => $d, 'hour' => $h, 'min' => $M, 'sec' => $s));
     if (empty($ai['end_date'])) {
         $y2 = $y;
         $m2 = $m;
         $d2 = $d;
         $h2 = $h;
         $M2 = $M + 15;
         $s2 = $s;
         if ($M2 > 60) {
             $M2 = $M2 - 60;