Browse Source

IMPROVED Category sessions, now can set empty end date. CT#1300

Alberto Torreblanca 14 years ago
parent
commit
57aa2879e5

+ 47 - 45
main/admin/session_category_add.php

@@ -165,60 +165,62 @@ for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
   <td width="20%"><?php echo get_lang('DateEnd') ?>&nbsp;&nbsp;</td>
   <td width="80%">
   <select name="day_end">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_end == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_end == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_end == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_end == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_end == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_end == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_end == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_end == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_end == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_end == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_end == 12)) echo 'selected="selected"'; ?> >12</option>
-	<option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_end == 13)) echo 'selected="selected"'; ?> >13</option>
-	<option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_end == 14)) echo 'selected="selected"'; ?> >14</option>
-	<option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_end == 15)) echo 'selected="selected"'; ?> >15</option>
-	<option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_end == 16)) echo 'selected="selected"'; ?> >16</option>
-	<option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_end == 17)) echo 'selected="selected"'; ?> >17</option>
-	<option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_end == 18)) echo 'selected="selected"'; ?> >18</option>
-	<option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_end == 19)) echo 'selected="selected"'; ?> >19</option>
-	<option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_end == 20)) echo 'selected="selected"'; ?> >20</option>
-	<option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_end == 21)) echo 'selected="selected"'; ?> >21</option>
-	<option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_end == 22)) echo 'selected="selected"'; ?> >22</option>
-	<option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_end == 23)) echo 'selected="selected"'; ?> >23</option>
-	<option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_end == 24)) echo 'selected="selected"'; ?> >24</option>
-	<option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_end == 25)) echo 'selected="selected"'; ?> >25</option>
-	<option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_end == 26)) echo 'selected="selected"'; ?> >26</option>
-	<option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_end == 27)) echo 'selected="selected"'; ?> >27</option>
-	<option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_end == 28)) echo 'selected="selected"'; ?> >28</option>
-	<option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_end == 29)) echo 'selected="selected"'; ?> >29</option>
-	<option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_end == 30)) echo 'selected="selected"'; ?> >30</option>
-	<option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_end == 31)) echo 'selected="selected"'; ?> >31</option>
+	<option value="0">--</option>
+    <option value="1">01</option>
+	<option value="2">02</option>
+	<option value="3">03</option>
+	<option value="4">04</option>
+	<option value="5">05</option>
+	<option value="6">06</option>
+	<option value="7">07</option>
+	<option value="8">08</option>
+	<option value="9">09</option>
+	<option value="10">10</option>
+	<option value="11">11</option>
+	<option value="12">12</option>
+	<option value="13">13</option>
+	<option value="14">14</option>
+	<option value="15">15</option>
+	<option value="16">16</option>
+	<option value="17">17</option>
+	<option value="18">18</option>
+	<option value="19">19</option>
+	<option value="20">20</option>
+	<option value="21">21</option>
+	<option value="22">22</option>
+	<option value="23">23</option>
+	<option value="24">24</option>
+	<option value="25">25</option>
+	<option value="26">26</option>
+	<option value="27">27</option>
+	<option value="28">28</option>
+	<option value="29">29</option>
+	<option value="30">30</option>
+	<option value="31">31</option>
   </select>
   /
   <select name="month_end">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_end == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_end == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_end == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_end == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_end == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_end == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_end == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_end == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_end == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_end == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_end == 12)) echo 'selected="selected"'; ?> >12</option>
+	<option value="0">--</option>
+    <option value="1">01</option>
+	<option value="2">02</option>
+	<option value="3">03</option>
+	<option value="4">04</option>
+	<option value="5">05</option>
+	<option value="6">06</option>
+	<option value="7">07</option>
+	<option value="8">08</option>
+	<option value="9">09</option>
+	<option value="10">10</option>
+	<option value="11">11</option>
+	<option value="12">12</option>
   </select>
   /
   <select name="year_end">
-
+    <option value="0">----</option>
 <?php
 for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
 ?>
-	<option value="<?php echo $i; ?>" <?php if((!$formSent && ($thisYear+1) == $i) || ($formSent && $year_end == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
+	<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
 <?php
 }
 ?>

+ 10 - 8
main/admin/session_category_edit.php

@@ -156,7 +156,8 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
   <td width="20%"><?php echo get_lang('DateEnd') ?>&nbsp;&nbsp;</td>
   <td width="80%">
   <select name="day_end">
-	<option value="1">01</option>
+	<option value="0">--</option>
+	<option value="1" <?php if($day_end == 1) echo 'selected="selected"'; ?> >01</option>
 	<option value="2" <?php if($day_end == 2) echo 'selected="selected"'; ?> >02</option>
 	<option value="3" <?php if($day_end == 3) echo 'selected="selected"'; ?> >03</option>
 	<option value="4" <?php if($day_end == 4) echo 'selected="selected"'; ?> >04</option>
@@ -190,7 +191,8 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
   </select>
   /
   <select name="month_end">
-	<option value="1">01</option>
+	<option value="0">--</option>
+	<option value="1" <?php if($month_end == 1) echo 'selected="selected"'; ?> >01</option>
 	<option value="2" <?php if($month_end == 2) echo 'selected="selected"'; ?> >02</option>
 	<option value="3" <?php if($month_end == 3) echo 'selected="selected"'; ?> >03</option>
 	<option value="4" <?php if($month_end == 4) echo 'selected="selected"'; ?> >04</option>
@@ -205,12 +207,12 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
   </select>
   /
   <select name="year_end">
-
-<?php
-for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
-{ ?>
-	<option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
-<?php
+     <option value="0">----</option>
+    <?php
+    for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
+    { ?>
+     <option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
+    <?php
 } ?>
   </select>
   </td>

+ 25 - 15
main/inc/lib/sessionmanager.lib.php

@@ -805,7 +805,7 @@ class SessionManager {
 		$day_end=intval($sday_end);
 
 		$date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
-		$date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
+		$date_end = "'$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end)."'";
 
 		if (empty($name)) {
 			$msg=get_lang('SessionCategoryNameIsRequired');
@@ -813,22 +813,25 @@ class SessionManager {
 		} elseif (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start)) {
 			$msg=get_lang('InvalidStartDate');
 			return $msg;
+        } elseif (!$month_end && !$day_end && !$year_end) {
+            $date_end = 'null';
 		} elseif (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end)) {
 			$msg=get_lang('InvalidEndDate');
 			return $msg;
 		} elseif($date_start >= $date_end) {
 			$msg=get_lang('StartDateShouldBeBeforeEndDate');
 			return $msg;
-		} else {
-			$sql = "INSERT INTO $tbl_session_category(name, date_start, date_end) VALUES('".Database::escape_string($name)."','$date_start','$date_end')";
-			Database::query($sql);
-			$id_session=Database::insert_id();
-			// add event to system log
-			$time = time();
-			$user_id = api_get_user_id();
-			event_system(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, $time, $user_id);
-			return $id_session;
 		}
+        $sql = "INSERT INTO $tbl_session_category(name, date_start, date_end)
+        VALUES('".Database::escape_string($name)."','$date_start',$date_end)";
+        Database::query($sql);
+        $id_session=Database::insert_id();
+        // add event to system log
+        $time = time();
+        $user_id = api_get_user_id();
+        event_system(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, $time, $user_id);
+        return $id_session;
+
 	}
 
 	/**
@@ -864,18 +867,25 @@ class SessionManager {
 		} elseif (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start)) {
 			$msg=get_lang('InvalidStartDate');
 			return $msg;
+		} elseif (!$month_end && !$day_end && !$year_end) {
+            $date_end = null;
 		} elseif (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end)) {
 			$msg=get_lang('InvalidEndDate');
 			return $msg;
 		} elseif($date_start >= $date_end) {
 			$msg=get_lang('StartDateShouldBeBeforeEndDate');
 			return $msg;
-		} else {
-			$sql = "UPDATE $tbl_session_category SET name = '".Database::escape_string($name)."', date_start = '$date_start', date_end = '$date_end'
-					WHERE id= '".$id."' ";
-			$result = Database::query($sql);
-			return ($result? true:false);
 		}
+        if ( $date_end <> null ) {
+	        $sql = "UPDATE $tbl_session_category SET name = '".Database::escape_string($name)."', date_start = '$date_start' ".
+                ", date_end = '$date_end' WHERE id= '".$id."' ";
+        } else {
+            $sql = "UPDATE $tbl_session_category SET name = '".Database::escape_string($name)."', date_start = '$date_start' ".
+                ", date_end = NULL WHERE id= '".$id."' ";
+        }
+		$result = Database::query($sql);
+		return ($result? true:false);
+
 	}
 
 	/**