00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00071 function checkIfNotNegDate($neg_startTime, $neg_ID, $neg_dates){
00072 $notNeg = TRUE;
00073 $neg_startTime = mktime(0, 0, 0, date("m", $neg_startTime), date ("d", $neg_startTime), date("Y", $neg_startTime));
00074 if($neg_dates){
00075 foreach ($neg_dates as $key => $ArrayRow)
00076 {
00077 if ($ArrayRow[9] == $neg_startTime && $ArrayRow[0]== $neg_ID) {$notNeg =FALSE; break; }
00078 }
00079 }
00080 return $notNeg;
00081 }
00082
00083
00084
00085
00086
00103 function cmp ($a, $b) {
00104 if ($a[1] == $b[1]) return 0;
00105 return ($a[1] < $b[1]) ? -1 : 1;
00106 }
00107
00108
00109
00110
00127 function getDateList($id, $start, $end, $Keywords, $DB){
00128 $neg_dates = $DB->getNegRotationDates ($id, $start, $end);
00129 $resultRotation = $DB->getRotationDates($id, $start, $end, $Keywords);
00130 $resultArray = $DB->getDates($id, $start, $end, $Keywords);
00131 if ($resultRotation && $resultArray) {
00132 $rotationDates = calculateDatesFromRotatation($start, $end, $resultRotation, $neg_dates);
00133 $result = array_merge($resultArray, $rotationDates) ;
00134 usort($result, "cmp");
00135 }
00136 if (!$resultRotation && $resultArray){
00137 $result = $resultArray;
00138 }
00139 if ($resultRotation && !$resultArray) {
00140 $rotationDates = calculateDatesFromRotatation($start, $end, $resultRotation, $neg_dates);
00141 $result = $rotationDates;
00142 usort($result, "cmp");
00143 }
00144 if (!$resultRotation && !$resultArray) {
00145 $result = FALSE;
00146 }
00147
00148 return $result;
00149 }
00150
00151
00152
00153
00170 function getWholeDayDateList($id, $start, $end, $Keywords, $DB){
00171 $neg_dates = $DB->getNegRotationDates ($id, $start, $end);
00172 $resultRotation = $DB->getFullDayRotationDates($id, $start, $end, $Keywords);
00173 $resultArray = $DB->getFullDayDates($id, $start, $end, $Keywords);
00174 if ($resultRotation && $resultArray) {
00175 $rotationDates = calculateDatesFromRotatation($start, $end, $resultRotation, $neg_dates);
00176 $result = array_merge($resultArray, $rotationDates) ;
00177 usort($result, "cmp");
00178 }
00179 if (!$resultRotation && $resultArray){
00180 $result = $resultArray;
00181 }
00182 if ($resultRotation && !$resultArray) {
00183 $rotationDates = calculateDatesFromRotatation($start, $end, $resultRotation, $neg_dates);
00184 $result = $rotationDates;
00185 usort($result, "cmp");
00186 }
00187 if (!$resultRotation && !$resultArray) {
00188 $result = FALSE;
00189 }
00190 return $result;
00191 }
00192
00193
00194
00195
00196
00212 function getDayList($id, $start, $end, $Keywords, $DB){
00213 $unstreamedDates= getDateList($id, $start, $end, $Keywords, $DB);
00214
00215
00216
00217 if($unstreamedDates){
00218
00219
00220 $streamedDates[0][0][0]= $unstreamedDates[0][0];
00221 $streamedDates[0][0][1]= $unstreamedDates[0][1];
00222 $streamedDates[0][0][2]= $unstreamedDates[0][2];
00223 $streamedDates[0][0][3]= $unstreamedDates[0][5];
00224 $streamedDates[0][0][4]= $unstreamedDates[0][6];
00225
00226
00227 for($i=1;$i<count($unstreamedDates);$i++){
00228 $newstart = $unstreamedDates[$i][1];
00229 $newend = $unstreamedDates[$i][2];
00230 $stream=0;
00231 while (($newstart < $streamedDates[$stream][(count($streamedDates[$stream])-1)][2])
00232 || ($newstart == $streamedDates[$stream][(count($streamedDates[$stream])-1)][1]) ){
00233 $stream++;
00234 }
00235 $row =count($streamedDates[$stream]);
00236 $streamedDates[$stream][$row][0] = $unstreamedDates[$i][0];
00237 $streamedDates[$stream][$row][1] = $unstreamedDates[$i][1];
00238 $streamedDates[$stream][$row][2] = $unstreamedDates[$i][2];
00239 $streamedDates[$stream][$row][3] = $unstreamedDates[$i][5];
00240 $streamedDates[$stream][$row][4] = $unstreamedDates[$i][6];
00241 }
00242 }
00243 else{
00244 $streamedDates = false;
00245
00246 }
00247 return $streamedDates;
00248
00249 }
00250
00251
00252
00253
00267 function calculateDatesFromRotatation($startResultSlot, $endResultSlot, $resultRotation, $neg_dates){
00268 $resultRotationCalculation = array();
00269 $counter = 0;
00270 for($i=0; $i< count($resultRotation); $i++){
00271 $rotArg = $resultRotation[$i][7];
00272 switch($rotArg){
00273 case 1: $offset="+1 Day"; break;
00274 case 2: $offset="+1 week"; break;
00275 case 3: $offset="+2 week"; break;
00276 case 4: $offset="+4 week"; break;
00277 case 5: $offset="+1 month"; break;
00278 case 6: $offset="+6 month"; break;
00279 case 7: $offset="+1 year"; break;
00280 }
00281 $id = $resultRotation[$i][0];
00282 $start = $resultRotation[$i][1];
00283 $end = $resultRotation[$i][2];
00284 $short = $resultRotation[$i][5];
00285 $text = $resultRotation[$i][6];
00286 $endrotation = $resultRotation[$i][8];
00287
00288
00289 while($startResultSlot>$end){
00290 $start = strtotime($offset, $start);
00291 $end = strtotime($offset, $end);
00292 }
00293 while($endResultSlot>=$start && ($endrotation>= $start)){
00294 $isNoNegDate = checkIfNotNegDate($start, $id, $neg_dates);
00295 if($isNoNegDate){
00296 $resultRotationCalculation[$counter][0] = $id;
00297 $resultRotationCalculation[$counter][1] = $start;
00298 $resultRotationCalculation[$counter][2] = $end;
00299 $resultRotationCalculation[$counter][5] = $short;
00300 $resultRotationCalculation[$counter][6] = $text;
00301 $counter++;
00302 }
00303 $start = strtotime($offset, $start);
00304 $end = strtotime($offset, $end);
00305 }
00306 }
00307 return $resultRotationCalculation;
00308
00309 }
00310
00311
00326 function getGroupDatesForDisplay($groupID, $start, $end, $DB) {
00327 $GroupDates = $DB->getGroupDates($groupID, $start, $end);
00328 $GroupRotationDates = $DB->getGroupRotationDates ($groupID, $start, $end);
00329
00330
00331
00332 if ($GroupRotationDates && $GroupDates) {
00333 $rotationDates = calculateDatesFromRotatation($start, $end, $GroupRotationDates, $neg_dates);
00334 $result = array_merge($GroupDates, $rotationDates) ;
00335 usort($result, "cmp");
00336
00337 }
00338 if (!$GroupRotationDates && $GroupDates){
00339 $result = $GroupDates;
00340 }
00341 if ($GroupRotationDates && !$GroupDates) {
00342 $rotationDates = calculateDatesFromRotatation($start, $end, $GroupRotationDates, $neg_dates);
00343 $result = $rotationDates;
00344 usort($result, "cmp");
00345 }
00346 if (!$GroupRotationDates && !$GroupDates) {
00347 $result = FALSE;
00348 }
00349
00350 return $result;
00351
00352 }
00353
00354
00355
00356 ?>