Example #1
0
 function save()
 {
     function prep_month($ym, $periods, &$l, &$db_data)
     {
         foreach ($periods as $key => $value) {
             if ("{$ym}" . str_pad($key, 2, "0", STR_PAD_LEFT) > $l) {
                 foreach ($value as $period) {
                     $hour = explode(' ', $period);
                     //form the address
                     $address = '';
                     for ($i = 3; $i <= count($hour); $i++) {
                         $address .= $hour[$i] . ' ';
                     }
                     $db_data[] = array('worker_id' => $_SESSION['worker_id'], 'schedule_date' => "{$ym}" . str_pad($key, 2, "0", STR_PAD_LEFT), 'begin_hour' => $hour[0], 'end_hour' => $hour[2], 'address' => $address);
                 }
             }
         }
     }
     print_r($_POST['current_month']);
     $db_data = array();
     $l = date('Y-m-d', strtotime(date('Y-m-d') . " +1 day"));
     if (isset($_POST['current_month'])) {
         // Периоди за текущ месец -------------
         prep_month(date('Y-m') . '-', $_POST['current_month'], $l, $db_data);
     }
     if (isset($_POST['next_month'])) {
         // Периоди за следващ месец --------------
         prep_month(date('Y-m', strtotime(date('Y-m') . "-01 +1 month")) . '-', $_POST['next_month'], $l, $db_data);
     }
     $this->load->model('schedule_model');
     if (count($db_data)) {
         $this->schedule_model->remove_periods(array('worker_id' => $_SESSION['worker_id'], 'schedule_date >' => $l));
         $this->schedule_model->save_periods($db_data);
     }
     //    header('Content-Type: application/json');
     //    echo json_encode($response);
 }
Example #2
0
for ($i = 1; $i < 24; $i++) {
    echo "<td>{$i}<sup>00</sup></td>";
}
?>
<td></td></tr>
      </table>
    </div>
    <form id="schedule_months" action="schedule/save">
      <table id="s1" class='schedule'>
        <?php 
prep_month($ym, $periods);
?>
      </table>
      <table id="s2" class='schedule' style="display: none;">
        <?php 
prep_month(date('Y-m', strtotime($ym . "-01 +1month")), $periods);
?>
      </table>
    </form>
    <table class="sch_tit" style="border-top: 1px solid #000; margin-top: 1px;">
      <tr class="tr_tit"><td></td><?php 
for ($i = 1; $i < 24; $i++) {
    echo "<td>{$i}<sup>00</sup></td>";
}
?>
<td></td></tr>
      <tr>
        <td colspan="49" style="padding-top: 10px;">
          <div style="float: left">
            За да зявите период кликнете върху началния час и изберете продължителност.<br/>
            За да коригирате заявен период кликнете върху него.<br/>