Пример #1
0
function is_date($str)
{
    if (!empty($str) && trim($str) != '') {
        $str = str2mysqltime($str, 'Y-m-d');
        if ($str <= '1970-01-01') {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
Пример #2
0
function __datetime($fieldName, $attributes = array())
{
    global $date_format_convert;
    $strAttr = '';
    $name = '';
    $id = '';
    $f = explode('.', trim($fieldName));
    if (count($f) == 1) {
        if (isset($_POST[$fieldName])) {
            $attributes['value'] = $_POST[$fieldName];
        }
        $id = $fieldName;
        $name = $fieldName;
    } else {
        if (count($f) > 1) {
            $tmpValue = isset($attributes['value']) ? $attributes['value'] : null;
            $attributes['value'] = $_POST;
            foreach ($f as $k => $v) {
                if ($k == 0) {
                    $name = $v;
                    $id = $v;
                } else {
                    $name .= '[' . $v . ']';
                    $id .= ucfirst($v);
                }
            }
            foreach ($f as $k => $v) {
                if (isset($attributes['value'][$v])) {
                    $attributes['value'] = $attributes['value'][$v];
                } else {
                    if (empty($tmpValue)) {
                        unset($attributes['value']);
                    } else {
                        $attributes['value'] = $tmpValue;
                    }
                    break;
                }
            }
        }
    }
    if (!empty($attributes)) {
        if (isset($attributes['value'])) {
            if (is_date($attributes['value'])) {
                if (__DATE_FORMAT__ == 'dd/MM/yyyy') {
                    $attributes['value'] = str_replace('/', '-', $attributes['value']);
                }
                $attributes['value'] = str2mysqltime($attributes['value']);
                $attributes['value'] = date($date_format_convert[__DATE_FORMAT__] . ' H:i:s', strtotime($attributes['value']));
            } else {
                $attributes['value'] = '';
            }
        }
        foreach ($attributes as $k => $v) {
            $strAttr .= ' ' . htmlspecialchars($k) . '="' . htmlspecialchars($v) . '" ';
        }
    }
    $html = '<div class="input-append date" id="' . $id . '">
				<input type="text"  name="' . $name . '" ' . $strAttr . '  data-format="' . __DATE_FORMAT__ . ' hh:mm:ss" />
				<span class="add-on"><i class="icon-calendar"></i></span>
			  </div>
<script>
$(document).ready(function(){
   	$(\'#' . $id . '\').datetimepicker();
});
</script>';
    return $html;
}
Пример #3
0
 /**
  *
  */
 private function update()
 {
     $CI =& get_instance();
     $key = $CI->input->post('key');
     $auth_token = $CI->input->post('auth_token');
     $hook = Hook::singleton();
     foreach ($this->data[$this->conf['table']] as $k => $v) {
         if (isset($this->conf['form_elements'][$this->conf['table'] . '.' . $k]) && $this->conf['form_elements'][$this->conf['table'] . '.' . $k]['element'][0] == 'date') {
             if (__DATE_FORMAT__ == 'dd/MM/yyyy') {
                 $v = str_replace('/', '-', $v);
             }
             $v = str2mysqltime($v, 'Y-m-d');
         }
         if (isset($this->conf['form_elements'][$this->conf['table'] . '.' . $k]) && $this->conf['form_elements'][$this->conf['table'] . '.' . $k]['element'][0] == 'datetime') {
             if (__DATE_FORMAT__ == 'dd/MM/yyyy') {
                 $v = str_replace('/', '-', $v);
             }
             $v = str2mysqltime($v, 'Y-m-d H:i:s');
         }
         if (is_array($v)) {
             $this->data[$this->conf['table']][$k] = ',' . implode(',', $v) . ',';
         } else {
             $this->data[$this->conf['table']][$k] = $v;
         }
     }
     $crudAuth = $CI->session->userdata('CRUD_AUTH');
     $historyDao = new ScrudDao('crud_histories', $CI->db);
     $history = array();
     $history['user_id'] = isset($crudAuth['id']) ? $crudAuth['id'] : 0;
     $history['user_name'] = isset($crudAuth['user_name']) ? $crudAuth['user_name'] : '';
     $history['history_table_name'] = $this->conf['table'];
     $history['history_date_time'] = date("Y-m-d H:i:s");
     if (count($_POST) > 0 && $this->validate() && $auth_token == $CI->session->userdata('auth_token_xtable')) {
         if ($hook->isExisted('SCRUD_BEFORE_SAVE')) {
             $this->data = $hook->filter('SCRUD_BEFORE_SAVE', $this->data);
         }
         $editFlag = false;
         foreach ($this->primaryKey as $f) {
             $ary = explode('.', $f);
             if (isset($key[$ary[0]][$ary[1]])) {
                 $editFlag = true;
             } else {
                 $editFlag = false;
                 break;
             }
         }
         $q = $this->queryString;
         $q['xtype'] = 'index';
         if (isset($q['key'])) {
             unset($q['key']);
         }
         if ($editFlag) {
             $params = array();
             $strCon = "";
             $aryVal = array();
             $_tmp = "";
             foreach ($this->primaryKey as $f) {
                 $ary = explode('.', $f);
                 $strCon .= $_tmp . $f . ' = ?';
                 $_tmp = " AND ";
                 $aryVal[] = $key[$ary[0]][$ary[1]];
             }
             if ($this->globalAccess == false && !empty($crudAuth) && in_array($this->conf['table'] . '.created_by', $this->fields)) {
                 $strCon .= ' ' . $_tmp . $this->conf['table'] . '.created_by = ' . $crudAuth['id'] . ' ';
                 $_tmp = 'AND ';
             }
             $params = array($strCon, $aryVal);
             try {
                 if ($hook->isExisted('SCRUD_BEFORE_UPDATE')) {
                     $this->data = $hook->filter('SCRUD_BEFORE_UPDATE', $this->data);
                 }
                 if (in_array($this->conf['table'] . '.modified_by', $this->fields)) {
                     $this->data[$this->conf['table']]['modified_by'] = $crudAuth['id'];
                 }
                 if (in_array($this->conf['table'] . '.modified', $this->fields)) {
                     $this->data[$this->conf['table']]['modified'] = date('Y-m-d H:i:s');
                 }
                 $this->dao->update($this->data[$this->conf['table']], $params);
                 $tmpData = $this->data[$this->conf['table']];
                 foreach ($this->primaryKey as $f) {
                     $ary = explode('.', $f);
                     $tmpData[$ary[1]] = $_POST['key'][$ary[0]][$ary[1]];
                 }
                 $history['history_data'] = json_encode($tmpData);
                 $history['history_action'] = 'update';
                 $historyDao->insert($history);
                 if ($hook->isExisted('SCRUD_COMPLETE_SAVE')) {
                     $hook->execute('SCRUD_COMPLETE_SAVE', $this->data);
                 }
                 if ($hook->isExisted('SCRUD_COMPLETE_UPDATE')) {
                     $hook->execute('SCRUD_COMPLETE_UPDATE', $this->data);
                 }
                 header("Location: ?" . http_build_query($q, '', '&'));
             } catch (Exception $e) {
                 $this->errors['__NO_FIELD__'][] = $e->getMessage();
                 if (is_file($this->conf['theme_path'] . '/form.php')) {
                     require_once $this->conf['theme_path'] . '/form.php';
                 } else {
                     die($this->conf['theme_path'] . '/form.php is not found.');
                 }
             }
         } else {
             try {
                 if ($hook->isExisted('SCRUD_BEFORE_INSERT')) {
                     $this->data = $hook->filter('SCRUD_BEFORE_INSERT', $this->data);
                 }
                 if (in_array($this->conf['table'] . '.created_by', $this->fields)) {
                     $this->data[$this->conf['table']]['created_by'] = $crudAuth['id'];
                 }
                 if (in_array($this->conf['table'] . '.created', $this->fields)) {
                     $this->data[$this->conf['table']]['created'] = date('Y-m-d H:i:s');
                 }
                 $this->dao->insert($this->data[$this->conf['table']]);
                 $history['history_data'] = json_encode($this->data[$this->conf['table']]);
                 $history['history_action'] = 'add';
                 $historyDao->insert($history);
                 if ($hook->isExisted('SCRUD_COMPLETE_SAVE')) {
                     $hook->execute('SCRUD_COMPLETE_SAVE', $this->data);
                 }
                 if ($hook->isExisted('SCRUD_COMPLETE_INSERT')) {
                     $hook->execute('SCRUD_COMPLETE_INSERT', $this->data);
                 }
                 header("Location: ?" . http_build_query($q, '', '&'));
             } catch (Exception $e) {
                 $this->errors['__NO_FIELD__'][] = $e->getMessage();
                 if (is_file($this->conf['theme_path'] . '/form.php')) {
                     require_once $this->conf['theme_path'] . '/form.php';
                 } else {
                     die($this->conf['theme_path'] . '/form.php is not found.');
                 }
             }
             $CI->session->unset_userdata('xtable_search_conditions');
         }
     } else {
         if ($auth_token != $CI->session->userdata('auth_token_xtable')) {
             $this->errors['auth_token'][] = 'Auth token does not exist.';
         }
         if (is_file($this->conf['theme_path'] . '/form.php')) {
             require_once $this->conf['theme_path'] . '/form.php';
         } else {
             die($this->conf['theme_path'] . '/form.php is not found.');
         }
     }
 }
Пример #4
0
 function datetime($datetime)
 {
     $date = str2mysqltime($date);
     if (!is_date($date)) {
         $date = '';
     }
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\$/", $datetime, $matches)) {
         if (checkdate($matches[2], $matches[3], $matches[1])) {
             return true;
         }
     }
     return false;
 }