Esempio n. 1
0
 /**
  * create timer
  */
 public function mainReaction()
 {
     $date = VarDte::sanitize($_POST['date'], $err);
     $start = VarTim::sanitize($_POST['start_time'], $err);
     $stop = VarTim::sanitize($_POST['stop_time'], $err);
     $spent = VarDur::sanitize($_POST['spent'], $err);
     $this->data = new TimerModel();
     $this->data->set('task_id', $_POST['id']);
     if ($start) {
         $this->data->set('start', $_POST['date'] . ' ' . $_POST['start_time']);
     }
     if ($stop) {
         $this->data->set('stop', $_POST['date'] . ' ' . $_POST['stop_time']);
     }
     if ($spent) {
         $this->data->set('spent', $_POST['spent']);
     }
     /*
     echo '<pre>';
     print_r($_POST);
     echo "\n\n";
     echo "date : $date\n";
     echo "start : $start : ".$this->data->get('start')."\n";
     echo "stop : $stop : ".$this->data->get('stop')."\n";
     echo "spent: $spent\n";
     echo '</pre>';
     */
     $this->data->setCheck();
     if ($this->data->check()) {
         $this->data->connectDb();
         $this->data->set('manual', 1);
         $this->data->insert();
     }
     /*		
     echo $this->data;
     exit;
     */
     echo '<script type="text/javascript">';
     echo "reloadList(); window.setTimeout('\$.fn.colorbox.close()',1000);";
     echo '</script>';
     echo '<p class="empty">' . TR::html('message', 'time_added') . '</p>';
     return false;
 }
Esempio n. 2
0
 public static function sanitize($val, &$info)
 {
     if (empty($val)) {
         return '0000-00-00 00:00:00';
     }
     if (preg_match('/^[0|2|9][0|1|9][0-9]{2}\\-[0-1][0-9]\\-[0-3][0-9]( ([0-2][0-9]\\:[0-5][0-9])(\\:[0-5][0-9])?)?$/', $val)) {
         // SQL format, return as it is (no timezone evaluation)
         return $val;
     }
     if ($val == 'NOW') {
         return APP_SQL_NOW;
     }
     $d = '';
     $t = 0;
     $arr = explode(' ', $val);
     foreach ($arr as $v) {
         if ($tmp = VarTim::sanitize($v, $err)) {
             $t = $tmp;
         } else {
             if ($tmp = VarDte::sanitize($v, $err)) {
                 $d = $tmp;
             }
         }
     }
     if ($d && is_integer($t)) {
         $dh = 3600 * 24;
         if ($t < 0) {
             // got to go one day back
             $d = strftime(APP_DATE_SQL, strtotime($d) - $dh);
             $t = $dh + $t;
             // + means - as $t is < 0
         } else {
             if ($t > $dh) {
                 // got to move on one day
                 $d = strftime(APP_DATE_SQL, strtotime($d) + $dh);
                 $t = $t - $dh;
             }
         }
         // return datetime in SQL format
         return $d . ' ' . VarDur::workout($t);
     }
     $info['error'] = 'invalid_datetime';
     return false;
 }