Changeset 1678

Show
Ignore:
Timestamp:
04/20/06 01:17:57 (7 years ago)
Author:
qldrob
Message:

#679 - antoniofcano supplied a nice little rewrite to time conditions. It needs some java verification still, but it's good enough to play with.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.1/timeconditions/functions.inc.php

    r956 r1678  
    6868} 
    6969 
     70function get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) { 
     71 
     72        //----- Time Hour Interval proccess ---- 
     73        if ($minute_start == '-') { 
     74            $time_minute_start = 0; 
     75         } else { 
     76            $time_minute_start = $minute_start; 
     77         } 
     78         if ($minute_finish == '-') { 
     79            $time_minute_finish = 0; 
     80         } else { 
     81             $time_minute_finish = $minute_finish; 
     82         } 
     83         if ($hour_start == '-') { 
     84             $time_hour_start = '*'; 
     85          } else { 
     86             $time_hour_start = $hour_start . ':' . $time_minute_start; 
     87          } 
     88          if ($hour_finish == '-') { 
     89             $time_hour_finish = '*'; 
     90          } else { 
     91             $time_hour_finish = $hour_finish . ':' . $time_minute_finish; 
     92          } 
     93          if ($time_hour_start == $time_hour_finish) { 
     94              $time_hour = $time_hour_start; 
     95          } else { 
     96              $time_hour = $time_hour_start . '-' . $time_hour_finish; 
     97          } 
     98          //----- Time Week Day Interval proccess ----- 
     99          if ($wday_start == '-') { 
     100              $time_wday_start = '*'; 
     101           } else { 
     102              $time_wday_start = $wday_start; 
     103           } 
     104           if ($wday_finish == '-') { 
     105              $time_wday_finish = '*'; 
     106           } else { 
     107              $time_wday_finish = $wday_finish; 
     108           } 
     109           if ($time_wday_start == $time_wday_finish) { 
     110               $time_wday = $time_wday_start; 
     111            } else { 
     112               $time_wday = $time_wday_start . '-' . $time_wday_finish; 
     113            } 
     114            //----- Time Month Day Interval proccess ----- 
     115            if ($mday_start == '-') { 
     116               $time_mday_start = '*'; 
     117            } else { 
     118                $time_mday_start = $mday_start; 
     119            } 
     120            if ($mday_finish == '-') { 
     121                $time_mday_finish = '*'; 
     122            } else { 
     123                $time_mday_finish = $mday_finish; 
     124            } 
     125            if ($time_mday_start == $time_mday_finish) { 
     126                $time_mday = $time_mday_start; 
     127            } else { 
     128                $time_mday = $time_mday_start . '-' . $time_mday_finish; 
     129            } 
     130            //----- Time Month Interval proccess ----- 
     131            if ($month_start == '-') { 
     132                $time_month_start = '*'; 
     133            } else { 
     134                $time_month_start = $month_start; 
     135            } 
     136            if ($month_finish == '-') { 
     137                $time_month_finish = '*'; 
     138            } else { 
     139                $time_month_finish = $month_finish; 
     140            } 
     141            if ($time_month_start == $time_month_finish) { 
     142                $time_month = $time_month_start; 
     143            } else { 
     144                $time_month = $time_month_start . '-' . $time_month_finish; 
     145            } 
     146      $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month; 
     147      return $time; 
     148} 
     149 
    70150function timeconditions_add($post){ 
    71151  if(!timeconditions_chk($post)) 
    72152    return false; 
    73153  extract($post); 
     154 
     155        $time = get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish); 
     156 
    74157  if(empty($displayname)) $displayname = "unnamed"; 
    75158  $results = sql("INSERT INTO timeconditions (displayname,time,truegoto,falsegoto,deptname) values (\"$displayname\",\"$time\",\"${$goto0.'0'}\",\"${$goto1.'1'}\",\"$deptname\")"); 
     
    80163    return false; 
    81164  extract($post); 
     165 
     166        $time = get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish); 
     167   
    82168  if(empty($displayname)) $displayname = "unnamed"; 
    83169  $results = sql("UPDATE timeconditions SET displayname = \"$displayname\", time = \"$time\", truegoto = \"${$goto0.'0'}\", falsegoto = \"${$goto1.'1'}\", deptname = \"$deptname\" WHERE timeconditions_id = \"$id\""); 
  • modules/branches/2.1/timeconditions/page.timeconditions.php

    r1201 r1678  
    139139  <tr> 
    140140    <td><a href="#" class="info"><?php echo _("Time to match:")?><span><?php echo _("time range|days of week|days of month|months<br><br>you can use an * as a wildcard.<br><br>ex: <b>9:00-17:00|mon-fri|*|*</b>")?></span></a></td> 
    141     <td><input type="text" name="time" value="<?php echo (isset($thisItem['time']) ? $thisItem['time'] : ''); ?>"></td> 
     141               <?php 
     142                   // ----- Load Time Pattern Variables ----- 
     143                   list($time_hour, $time_wday, $time_mday, $time_month) = explode( '|', $thisItem['time'] ); 
     144               ?> 
     145               <tr> 
     146                   <td><?php echo _("Time to start:")?></td> 
     147                   <td> 
     148                       <?php 
     149                           // Hour could be *, hh:mm, hh:mm-hhmm 
     150                           if ( $time_hour != '*' ) { 
     151                               list($hour_start_string, $hour_finish_string) = explode('-', $time_hour); 
     152                               list($hour_start, $minute_start) = explode( ':', $hour_start_string); 
     153                               list($hour_finish, $minute_finish) = explode( ':', $hour_finish_string); 
     154                               if ( !$hour_finish ) $hour_finish = $hour_start; 
     155                               if ( !$minute_finish ) $minute_finish = $minute_start; 
     156                           } else { 
     157                               $hour_start = $hour_finish = '-'; 
     158                               $minute_start = $minute_finish = '-'; 
     159                           } 
     160                       ?> 
     161                        <select name="hour_start"/> 
     162                        <?php 
     163                           $default = ''; 
     164                            if ( $hour_start == '-' ) $default = ' selected'; 
     165                            echo "<option value=\"-\" $default>-"; 
     166                            for ($i = 0 ; $i < 24 ; $i++) { 
     167                               $default = ""; 
     168                               if ( $i == $hour_start ) $default = ' selected'; 
     169                                echo "<option value=\"$i\" $default> ".sprintf("%02d", $i); 
     170                            } 
     171                        ?> 
     172                        </select> 
     173                       <nbsp>:<nbsp> 
     174                        <select name="minute_start"/> 
     175                        <?php 
     176                           $default = ''; 
     177                            if ( $minute_start == '-' ) $default = ' selected'; 
     178                            echo "<option value=\"-\" $default>-"; 
     179                            for ($i = 0 ; $i < 60 ; $i++) { 
     180                                $default = ""; 
     181                                if ( $i == $minute_start ) $default = ' selected'; 
     182                                echo "<option value=\"$i\" $default> ".sprintf("%02d", $i); 
     183                            } 
     184                        ?> 
     185                        </select> 
     186                    </td> 
     187               </tr> 
     188               <tr> 
     189                   <td><?php echo _("Time to finish:")?></td> 
     190                   <td> 
     191                        <select name="hour_finish"/> 
     192                        <?php 
     193                           $default = ''; 
     194                            if ( $hour_finish == '-' ) $default = ' selected'; 
     195                            echo "<option value=\"-\" $default>-"; 
     196                            for ($i = 0 ; $i < 24 ; $i++) { 
     197                                $default = ""; 
     198                                if ( $i == $hour_finish) $default = ' selected'; 
     199                                echo "<option value=\"$i\" $default> ".sprintf("%02d", $i); 
     200                            } 
     201                        ?> 
     202                        </select> 
     203                       <nbsp>:<nbsp> 
     204                        <select name="minute_finish"/> 
     205                        <?php 
     206                            $default = ''; 
     207                            if ( $minute_finish == '-' ) $default = ' selected'; 
     208                            echo "<option value=\"-\" $default>-"; 
     209                            for ($i = 0 ; $i < 60 ; $i++) { 
     210                               $default = ''; 
     211                                if ( $i == $minute_finish ) $default = ' selected'; 
     212                                echo "<option value=\"$i\" $default> ".sprintf("%02d", $i); 
     213                            } 
     214                        ?> 
     215                        </select> 
     216                    </td> 
     217               </tr> 
     218                <tr> 
     219                   <?php  
     220                         // WDay could be *, day, day1-day2 
     221                         if ( $time_wday != '*' ) { 
     222                             list($wday_start, $wday_finish) = explode('-', $time_wday); 
     223                             if ( !$wday_finish) $wday_finish = $wday_start; 
     224                         } else { 
     225                             $wday_start = $wday_finish = '-'; 
     226                         } 
     227                    ?> 
     228                   <td><?php echo _("Week Day Start:")?></td> 
     229                   <td> 
     230                       <select name="wday_start"/> 
     231                           <?php  
     232                               if ( $wday_start == '-' ) { $default = ' selected'; } 
     233                               else {$default = '';} 
     234                               echo "<option value=\"-\" $default>-"; 
     235  
     236                               if ( $wday_start == 'mon' ) { $default = ' selected'; } 
     237                                else {$default = '';} 
     238                               echo "<option value=\"mon\" $default>" . _("Monday"); 
     239 
     240                                if ( $wday_start == 'tue' ) { $default = ' selected'; } 
     241                               else {$default = '';} 
     242                                echo "<option value=\"tue\" $default>" . _("Tuesday"); 
     243 
     244                                if ( $wday_start == 'wed' ) { $default = ' selected'; } 
     245                               else {$default = '';} 
     246                                echo "<option value=\"wed\" $default>" . _("Wednesday"); 
     247 
     248                                if ( $wday_start == 'thu' ) { $default = ' selected'; } 
     249                                else {$default = '';} 
     250                                echo "<option value=\"thu\" $default>" . _("Thursday"); 
     251 
     252                                if ( $wday_start == 'fri' ) { $default = ' selected'; } 
     253                                else {$default = '';} 
     254                                echo "<option value=\"fri\" $default>" . _("Friday"); 
     255 
     256                                if ( $wday_start == 'sat' ) { $default = ' selected'; } 
     257                                else {$default = '';} 
     258                                echo "<option value=\"sat\" $default>" . _("Saturday"); 
     259 
     260                               if ( $wday_start == 'sun' ) { $default = ' selected'; } 
     261                                else {$default = '';} 
     262                                echo "<option value=\"sun\" $default>" . _("Sunday"); 
     263                       ?> 
     264           </td> 
     265               </tr> 
     266               <tr> 
     267                   <td><?php echo _("Week Day finish:")?></td> 
     268                   <td> 
     269                       <select name="wday_finish"/> 
     270                       <?php  
     271                               if ( $wday_finish == '-' ) { $default = ' selected'; } 
     272                               else {$default = '';} 
     273                               echo "<option value=\"-\" $default>-"; 
     274  
     275                               if ( $wday_finish == 'mon' ) { $default = ' selected'; } 
     276                                else {$default = '';} 
     277                               echo "<option value=\"mon\" $default>" . _("Monday"); 
     278 
     279                                if ( $wday_finish == 'tue' ) { $default = ' selected'; } 
     280                               else {$default = '';} 
     281                                echo "<option value=\"tue\" $default>" . _("Tuesday"); 
     282 
     283                                if ( $wday_finish == 'wed' ) { $default = ' selected'; } 
     284                               else {$default = '';} 
     285                                echo "<option value=\"wed\" $default>" . _("Wednesday"); 
     286 
     287                                if ( $wday_finish == 'thu' ) { $default = ' selected'; } 
     288                                else {$default = '';} 
     289                                echo "<option value=\"thu\" $default>" . _("Thursday"); 
     290 
     291                                if ( $wday_finish == 'fri' ) { $default = ' selected'; } 
     292                                else {$default = '';} 
     293                                echo "<option value=\"fri\" $default>" . _("Friday"); 
     294 
     295                                if ( $wday_finish == 'sat' ) { $default = ' selected'; } 
     296                                else {$default = '';} 
     297                                echo "<option value=\"sat\" $default>" . _("Saturday"); 
     298 
     299                               if ( $wday_finish == 'sun' ) { $default = ' selected'; } 
     300                                else {$default = '';} 
     301                                echo "<option value=\"sun\" $default>" . _("Sunday"); 
     302                       ?> 
     303                   </td> 
     304                </tr> 
     305                <tr> 
     306                   <td><?php echo _("Month Day start:")?></td> 
     307                    <?php 
     308                         // MDay could be *, day, day1-day2 
     309                         if ( $time_mday != '*' ) { 
     310                             list($mday_start, $mday_finish) = explode('-', $time_mday); 
     311                             if ( !$mday_finish) $mday_finish = $mday_start; 
     312                         } else { 
     313                             $mday_start = $mday_finish = '-'; 
     314                         } 
     315                   ?> 
     316                  <td> 
     317                        <select name="mday_start"/> 
     318                         <?php 
     319                            $default = ''; 
     320                            if ( $mday_start == '-' ) $default = ' selected'; 
     321                            echo "<option value=\"-\" $default>-"; 
     322                            for ($i = 1 ; $i < 32 ; $i++) { 
     323                                $default = ''; 
     324                                if ( $i == $mday_start ) $default = ' selected'; 
     325                                echo "<option value=\"$i\" $default> $i"; 
     326                            } 
     327                        ?> 
     328                        </select> 
     329                    </td> 
     330               <tr> 
     331                   <td><?php echo _("Month Day finish:")?></td> 
     332                  <td> 
     333                        <select name="mday_finish"/> 
     334                        <?php 
     335                            $default = ''; 
     336                            if ( $mday_finish == '-' ) $default = ' selected'; 
     337                            echo "<option value=\"-\" $default>-"; 
     338                            for ($i = 1 ; $i < 32 ; $i++) { 
     339                                $default = ''; 
     340                                if ( $i == $mday_finish ) $default = ' selected'; 
     341                                echo "<option value=\"$i\" $default> $i"; 
     342                            } 
     343                        ?> 
     344                        </select> 
     345                    </td> 
     346               </tr> 
     347                <tr> 
     348                   <td><?php echo _("Month start:")?></td> 
     349                     <?php 
     350                         // Month could be *, month, month1-month2 
     351                         if ( $time_month != '*' ) { 
     352                             list($month_start, $month_finish) = explode('-', $time_month); 
     353                             if ( !$month_finish) $month_finish = $month_start; 
     354                         } else { 
     355                             $month_start = $month_finish = '-'; 
     356                         } 
     357                   ?> 
     358                  <td> 
     359                        <select name="month_start"/> 
     360                            <?php    
     361                                if ( $month_start == '-' ) { $default = ' selected'; } 
     362                                else {$default = '';} 
     363                                echo "<option value=\"-\" $default>-"; 
     364                                if ( $month_start == 'jan' ) { $default = ' selected'; } 
     365                                else {$default = '';} 
     366                                echo "<option value=\"jan\" $default>" . _("January"); 
     367                                
     368                                if ( $month_start == 'feb' ) { $default = ' selected'; } 
     369                                else {$default = '';} 
     370                                echo "<option value=\"feb\" $default>" . _("February"); 
     371 
     372                                if ( $month_start == 'mar' ) { $default = ' selected'; } 
     373                                else {$default = '';} 
     374                                echo "<option value=\"mar\" $default>" . _("March"); 
     375                                
     376                                if ( $month_start == 'apr' ) { $default = ' selected'; } 
     377                                else {$default = '';} 
     378                                echo "<option value=\"apr\" $default>" . _("April"); 
     379  
     380                               if ( $month_start == 'may' ) { $default = ' selected'; } 
     381                                else {$default = '';} 
     382                                echo "<option value=\"may\" $default>" . _("May"); 
     383                                
     384                                if ( $month_start == 'jun' ) { $default = ' selected'; } 
     385                               else {$default = '';} 
     386                                echo "<option value=\"jun\" $default>" . _("June"); 
     387 
     388                                if ( $month_start == 'jul' ) { $default = ' selected'; } 
     389                                else {$default = '';} 
     390                                echo "<option value=\"jul\" $default>" . _("July"); 
     391                                
     392                                if ( $month_start == 'aug' ) { $default = ' selected'; } 
     393                                else {$default = '';} 
     394                                echo "<option value=\"aug\" $default>" . _("August"); 
     395  
     396                               if ( $month_start == 'sep' ) { $default = ' selected'; } 
     397                                else {$default = '';} 
     398                                echo "<option value=\"sep\" $default>" . _("September"); 
     399                                
     400                                if ( $month_start == 'oct' ) { $default = ' selected'; } 
     401                                else {$default = '';} 
     402                                echo "<option value=\"oct\" $default>" . _("October"); 
     403                                if ( $month_start == 'nov' ) { $default = ' selected'; } 
     404                                else {$default = '';} 
     405                                echo "<option value=\"nov\" $default>" . _("November"); 
     406                                
     407                                if ( $month_start == 'dec' ) { $default = ' selected'; } 
     408                                else {$default = '';} 
     409                                echo "<option value=\"dec\" $default>" . _("December"); 
     410                         ?> 
     411                       </select> 
     412                     </td> 
     413        </tr> 
     414                <tr> 
     415                    <td><?php echo _("Month finish:")?></td> 
     416                    <td> 
     417                        <select name="month_finish"/> 
     418                        <?php    
     419                                if ( $month_finish == '-' ) { $default = ' selected'; } 
     420                                else {$default = '';} 
     421                                echo "<option value=\"-\" $default>-"; 
     422                                if ( $month_finish == 'jan' ) { $default = ' selected'; } 
     423                                else {$default = '';} 
     424                                echo "<option value=\"jan\" $default>" . _("January"); 
     425                                
     426                                if ( $month_finish == 'feb' ) { $default = ' selected'; } 
     427                                else {$default = '';} 
     428                                echo "<option value=\"feb\" $default>" . _("February"); 
     429 
     430                                if ( $month_finish == 'mar' ) { $default = ' selected'; } 
     431                                else {$default = '';} 
     432                                echo "<option value=\"mar\" $default>" . _("March"); 
     433                                
     434                                if ( $month_finish == 'apr' ) { $default = ' selected'; } 
     435                                else {$default = '';} 
     436                                echo "<option value=\"apr\" $default>" . _("April"); 
     437  
     438                               if ( $month_finish == 'may' ) { $default = ' selected'; } 
     439                                else {$default = '';} 
     440                                echo "<option value=\"may\" $default>" . _("May"); 
     441                                
     442                                if ( $month_finish == 'jun' ) { $default = ' selected'; } 
     443                                else {$default = '';} 
     444                                echo "<option value=\"jun\" $default>" . _("June"); 
     445 
     446                                if ( $month_finish == 'jul' ) { $default = ' selected'; } 
     447                                else {$default = '';} 
     448                                echo "<option value=\"jul\" $default>" . _("July"); 
     449                                
     450                                if ( $month_finish == 'aug' ) { $default = ' selected'; } 
     451                                else {$default = '';} 
     452                                echo "<option value=\"aug\" $default>" . _("August"); 
     453  
     454                               if ( $month_finish == 'sep' ) { $default = ' selected'; } 
     455                                else {$default = '';} 
     456                                echo "<option value=\"sep\" $default>" . _("September"); 
     457                                
     458                               if ( $month_finish == 'oct' ) { $default = ' selected'; } 
     459                                else {$default = '';} 
     460                                echo "<option value=\"oct\" $default>" . _("October"); 
     461 
     462                                if ( $month_finish == 'nov' ) { $default = ' selected'; } 
     463                                else {$default = '';} 
     464                                echo "<option value=\"nov\" $default>" . _("November"); 
     465                                
     466                                if ( $month_finish == 'dec' ) { $default = ' selected'; } 
     467                                else {$default = '';} 
     468                                echo "<option value=\"dec\" $default>" . _("December"); 
     469                         ?> 
     470                         </select> 
     471                     </td> 
     472                </tr> 
    142473  </tr> 
    143474  <tr><td colspan="2"><br><h5><?php echo _("Destination if time matches")?>:<hr></h5></td></tr> 
    144  
    145475<?php  
    146476//draw goto selects