function ajax_arclist()
 {
     $prefix = !empty($_REQUEST['prefix']) ? (bool) $_REQUEST['prefix'] : true;
     //表过滤防止泄露信息,只允许的表
     if (!in_array($_REQUEST['model'], array('article', 'type', 'ad', 'label', 'link'))) {
         exit;
     }
     if (!empty($_REQUEST['model'])) {
         if ($prefix == true) {
             $model = C('DB_PREFIX') . $_REQUEST['model'];
         } else {
             $model = $_REQUEST['model'];
         }
     } else {
         $model = C('DB_PREFIX') . 'article';
     }
     $order = !empty($_REQUEST['order']) ? inject_check($_REQUEST['order']) : '';
     $num = !empty($_REQUEST['num']) ? inject_check($_REQUEST['num']) : '';
     $where = !empty($_REQUEST['where']) ? inject_check(urldecode($_REQUEST['where'])) : '';
     //使where支持 条件判断,添加不等于的判断
     $page = false;
     if (!empty($_REQUEST['page'])) {
         $page = (bool) $_REQUEST['page'];
     }
     $pagesize = !empty($_REQUEST['pagesize']) ? intval($_REQUEST['pagesize']) : '10';
     //$query     =!empty($_REQUEST['sql'])?$_REQUEST['sql']:'';//太危险不用
     $field = '';
     if (!empty($_REQUEST['field'])) {
         $f_t = explode(',', inject_check($_REQUEST['field']));
         $f_t = array_map('urlencode', $f_t);
         $field = implode(',', $f_t);
     }
     $m = new Model($model, NULL);
     //如果使用了分页,缓存也不生效
     if ($page) {
         import("ORG.Util.Page");
         //这里改成你的Page类
         $count = $m->where($where)->count();
         $total_page = ceil($count / $pagesize);
         $p = new Page($count, $pagesize);
         //如果使用了分页,num将不起作用
         $t = $m->field($field)->where($where)->limit($p->firstRow . ',' . $p->listRows)->order($order)->select();
         //echo $m->getLastSql();
         $ret = array('total_page' => $total_page, 'data' => $t);
     }
     //如果没有使用分页,并且没有 query
     if (!$page) {
         $ret = $m->field($field)->where($where)->order($order)->limit($num)->select();
     }
     $this->ajaxReturn($ret, '返回信息', 1);
 }
Example #2
0
 public function field($name, $conditions = null, $order = null)
 {
     if (isset($_SERVER['FORCEMASTER'])) {
         $this->useDbConfig = 'master';
     }
     return parent::field($name, $conditions, $order);
 }
 public function addToBasket(Model $Model, $id, array $options = array())
 {
     $options = Hash::merge(array('basket' => $Model->ShoppingBasketItem->ShoppingBasket->currentBasketId(), 'amount' => 1, 'configuration' => array(), 'non_overridable' => array()), array_filter($options));
     $configurationGroupIds = $Model->ItemConfigurationGroup->find('list', array('fields' => array('ConfigurationGroup.id'), 'conditions' => array('ItemConfigurationGroup.foreign_key' => $id, 'ItemConfigurationGroup.model' => $Model->name), 'contain' => array('ConfigurationGroup')));
     $valueData = $Model->ShoppingBasketItem->ConfigurationValue->generateValueData($Model->ShoppingBasketItem->name, $configurationGroupIds, $options['configuration'], $options['non_overridable']);
     $stackable = $Model->field('stackable', array('id' => $id));
     if ($stackable) {
         $shoppingBasketItemId = $Model->ShoppingBasketItem->field('id', array('ShoppingBasketItem.shopping_basket_id' => $options['basket'], 'ShoppingBasketItem.product_id' => $id));
         if (!$shoppingBasketItemId) {
             $Model->ShoppingBasketItem->create();
             $data = $Model->ShoppingBasketItem->saveAssociated(array('ShoppingBasketItem' => array('shopping_basket_id' => $options['basket'], 'product_id' => $id, 'amount' => $options['amount']), 'ConfigurationValue' => $valueData));
             return $data;
         }
         $Model->ShoppingBasketItem->id = $shoppingBasketItemId;
         $amount = $Model->ShoppingBasketItem->field('amount');
         return $Model->ShoppingBasketItem->saveField('amount', $amount + $options['amount']);
     }
     for ($number = 1; $number <= $options['amount']; $number++) {
         $Model->ShoppingBasketItem->create();
         $data = $Model->ShoppingBasketItem->saveAssociated(array('ShoppingBasketItem' => array('shopping_basket_id' => $options['basket'], 'product_id' => $id, 'amount' => 1), 'ConfigurationValue' => $valueData));
         if (!$data) {
             return false;
         }
     }
     return true;
 }
 public function moveOrder(Model $model, $data, $conditions = array())
 {
     $id = $data[$model->alias]['id'];
     $idField = $model->alias . '.id';
     $orderField = $model->alias . '.order';
     $move = $data[$model->alias]['move'];
     $order = $model->field('order', array('id' => $id));
     $idConditions = array_merge(array($idField => $id), $conditions);
     $updateConditions = array_merge(array($idField . ' <>' => $id), $conditions);
     $this->fixOrder($model, $conditions);
     if ($move === 'up') {
         $model->updateAll(array($orderField => $order - 1), $idConditions);
         $updateConditions[$orderField] = $order - 1;
         $model->updateAll(array($orderField => $order), $updateConditions);
     } else {
         if ($move === 'down') {
             $model->updateAll(array($orderField => $order + 1), $idConditions);
             $updateConditions[$orderField] = $order + 1;
             $model->updateAll(array($orderField => $order), $updateConditions);
         } else {
             if ($move === 'first') {
                 $model->updateAll(array($orderField => 1), $idConditions);
                 $updateConditions[$orderField . ' <'] = $order;
                 $model->updateAll(array($orderField => $orderField . ' + 1'), $updateConditions);
             } else {
                 if ($move === 'last') {
                     $count = $model->find('count', array('conditions' => $conditions));
                     $model->updateAll(array($orderField => $count), $idConditions);
                     $updateConditions[$orderField . ' >'] = $order;
                     $model->updateAll(array($orderField => $orderField . ' - 1'), $updateConditions);
                 }
             }
         }
     }
 }
Example #5
0
 public function deleteOldUpload(Model $model, $field)
 {
     $file = $model->field($field);
     if (empty($file)) {
         return true;
     }
     if (file_exists(WWW_ROOT . $file)) {
         unlink(WWW_ROOT . $file);
     }
 }
 function listall()
 {
     $projects = new Model('project');
     @($res = $projects->field('project_name,project_desc,project_hash,time,status')->where("user_hash = '" . $_SESSION['user_hash'] . "'")->select());
     //封装数组处理
     $url = new Model('url');
     foreach ($res as $key => &$value) {
         $value['shellnum'] = $url->where("project_hash = '" . $value['project_hash'] . "'")->count();
         $value['time'] = date('Y-m-d', $value['time']);
     }
     return $res;
 }
Example #7
0
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!empty($model->data[$model->name]['thumb']['name'])) {
         $file = $model->data[$model->name]['thumb'];
         // Current thumb
         $media_id = $model->field('media_id');
         if ($media_id != 0) {
             $model->Media->delete($media_id);
         }
         // Update thumb
         $model->Media->save(array('ref_id' => $model->id, 'ref' => $model->name, 'file' => $file));
         $model->saveField('media_id', $model->Media->id);
     }
 }
 public function getTask()
 {
     $objtask = new Model('project');
     $alltask = $objtask->field('project_hash,target,setting')->where("status = 0")->find();
     //处理exp数组
     if ($alltask) {
         $arr = array_merge($alltask, unserialize($alltask['setting']));
         unset($arr['setting']);
         //格式化与加密数据
         //echo str_replace("\\/","/",json_encode($arr));
         echo data_encode(str_replace("\\/", "/", json_encode($arr)), $this->key);
     } else {
         echo 'notask';
     }
 }
 public function deleteOldUpload(Model $model, $field)
 {
     $file = $model->field($field);
     if (empty($file)) {
         return true;
     }
     $info = pathinfo($file);
     $subfiles = glob(WWW_ROOT . $info['dirname'] . DS . $info['filename'] . '_*x*.*');
     if (file_exists(WWW_ROOT . $file)) {
         unlink(WWW_ROOT . $file);
     }
     if ($subfiles) {
         foreach ($subfiles as $file) {
             unlink($file);
         }
     }
 }
Example #10
0
 /**
  * parentNode
  *
  * @param Model $model
  * @return array
  */
 public function parentNode($model)
 {
     if (!$model->id && empty($model->data)) {
         return null;
     }
     $data = $model->data;
     if (empty($model->data)) {
         $data = $model->read();
     }
     if (!isset($data['User']['role_id'])) {
         $data['User']['role_id'] = $model->field('role_id');
     }
     if (!isset($data['User']['role_id']) || !$data['User']['role_id']) {
         return null;
     } else {
         return array('Role' => array('id' => $data['User']['role_id']));
     }
 }
 function delurl()
 {
     $urlhash = _get('get.token', null, '/^[a-z0-9]{30}$/');
     if ($urlhash) {
         //获取项目token
         $obj = new Model('url');
         $tokenarr = $obj->field('project_hash')->where("url_hash = '" . $urlhash . "'")->find();
         $token = $tokenarr['project_hash'];
         //项目token查用户hash权限判断
         $buffusers = new Model('project');
         $userhash = $buffusers->field('user_hash')->where("project_hash = '" . $token . "'")->find();
         if ($userhash['user_hash'] != $_SESSION['user_hash']) {
             exit;
         }
         if ($obj->where("url_hash = '" . $urlhash . "'")->del()) {
             $this->_ajaxReturn('删除成功', 'success', 'index.php?m=project&a=listurl&token=' . $token);
         }
     }
 }
 public function check()
 {
     $data['usrname'] = _get('post.username', null, '/[a-zA-Z0-9]{4,12}/');
     $data['usrpass'] = _get('post.password');
     $users = new Model('users');
     //用户验证
     if ($usr = $users->field('usrname,usrpass,user_hash')->where("usrname = '" . $data['usrname'] . "'")->find()) {
         if (_md5($data['usrpass'], 'codier', -20) == $usr['usrpass']) {
             //设置用户session
             $_SESSION['isLogin'] = true;
             $_SESSION['user_hash'] = $usr['user_hash'];
             $_SESSION['usrname'] = $usr['usrname'];
             $this->_ajaxReturn('登录成功', 'success', 'index.php?m=index&a=index');
         } else {
             $this->_ajaxReturn('用户名或者密码错误', 'prompt');
         }
     } else {
         $this->_ajaxReturn('用户名或者密码错误', 'prompt');
     }
 }
 public function increment(Model $Model, $id = null, $field = null)
 {
     if (!$field && key($this->settings[$Model->alias]['fields'])) {
         $field = key($this->settings[$Model->alias]['fields']);
     }
     if (!$field) {
         return false;
     }
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $Model->id = $id;
     $currentValue = $Model->field($field, array($Model->alias . '.id' => $id));
     $result = $Model->saveField($field, $currentValue + 1);
     if (!$result) {
         return false;
     }
     return $currentValue + 1;
 }
Example #14
0
 /**
  * Generates an array of params to be used in Router::url() to get a link to the reported object view page
  *
  * @param AppModel $Model
  * @param string $id the reported object identifier
  * @return array
  */
 public function reportedObjectUrl(Model $Model, $id)
 {
     $modelName = Configure::read('Problems.Models.' . $Model->alias);
     if ($Model->hasField('slug')) {
         $id = $Model->field('slug', array('id' => $id));
     }
     return array('admin' => false, 'controller' => Inflector::tableize($Model->name), 'action' => 'view', $id, 'plugin' => current(pluginSplit($modelName)));
 }
 /**
  * PasswordableBehavior::_validateSameHash()
  *
  * @param Model $Model
  * @param string $pwd
  * @return bool Success
  */
 protected function _validateSameHash(Model $Model, $pwd)
 {
     $field = $this->settings[$Model->alias]['field'];
     $type = $this->settings[$Model->alias]['hashType'];
     $salt = $this->settings[$Model->alias]['hashSalt'];
     if ($this->settings[$Model->alias]['authType'] === 'Blowfish') {
         $type = 'blowfish';
         $salt = false;
     }
     $primaryKey = $Model->data[$Model->alias][$Model->primaryKey];
     $dbValue = $Model->field($field, [$Model->primaryKey => $primaryKey]);
     if (!$dbValue && $pwd) {
         return false;
     }
     if ($type === 'blowfish' && function_exists('password_hash') && !empty($this->settings[$Model->alias]['passwordHasher'])) {
         $value = $pwd;
     } else {
         if ($type === 'blowfish') {
             $salt = $dbValue;
         }
         $value = Security::hash($pwd, $type, $salt);
     }
     if ($type === 'blowfish' && function_exists('password_hash') && !empty($this->settings[$Model->alias]['passwordHasher'])) {
         $PasswordHasher = $this->_getPasswordHasher($this->settings[$Model->alias]['passwordHasher']);
         return $PasswordHasher->check($value, $dbValue);
     }
     return $value === $dbValue;
 }
Example #16
0
 /**
  * beforeSave method
  *
  * If attempting to change the password, email or username make a note to be able to mail the user if successful
  *
  * @access public
  * @return void
  */
 function beforeSave(Model $Model)
 {
     extract($this->settings[$Model->alias]['fields']);
     if ($Model->id) {
         if (isset($Model->data[$Model->alias][$password]) && $Model->data[$Model->alias][$password] != $Model->field($password)) {
             $this->settings[$Model->alias]['__passwordChanged'] = true;
         }
         if (!empty($Model->data[$Model->alias][$email]) && $Model->data[$Model->alias][$email] != $Model->field($email)) {
             $this->settings[$Model->alias]['__emailChanged'] = $Model->field($email);
         }
         if ($email != $username && isset($Model->data[$Model->alias][$username]) && $Model->data[$Model->alias][$username] != $Model->field($username)) {
             $this->settings[$Model->alias]['__usernameChanged'] = $Model->field($username);
         }
     }
     return $Model->data;
 }
Example #17
0
 /**
  * Updates the computed cache of belongsTo associations after a save or delete operation.
  *
  * @param Model $Model
  * @param array $keys Optional foreign key data, defaults to the information `$this->data`.
  * @param boolean $created True if a new record was created, otherwise only associations with
  *   'computedScope' defined get updated
  * @return void
  */
 public function updateComputedCache(Model $Model, $keys = array(), $created = false)
 {
     $keys = empty($keys) ? $Model->data[$Model->alias] : $keys;
     $keys['old'] = isset($keys['old']) ? $keys['old'] : array();
     foreach ($Model->belongsTo as $parent => $assoc) {
         if (empty($assoc['computedCache'])) {
             continue;
         }
         if (!is_array($assoc['computedCache'])) {
             if (isset($assoc['computedScope'])) {
                 $assoc['computedCache'] = array($assoc['computedCache'] => $assoc['computedScope']);
             } else {
                 $assoc['computedCache'] = array($assoc['computedCache'] => array());
             }
         }
         $foreignKey = $assoc['foreignKey'];
         $fkQuoted = $Model->escapeField($assoc['foreignKey']);
         foreach ($assoc['computedCache'] as $field => $conditions) {
             if (!is_string($field)) {
                 $field = sprintf('%s_%s_computed', Inflector::underscore($Model->alias), $this->_methods[strtolower($this->settings[$Model->alias]['method'])]);
             }
             if (!$Model->{$parent}->hasField($field)) {
                 continue;
             }
             if ($conditions === true) {
                 $conditions = array();
             } else {
                 $conditions = (array) $conditions;
             }
             if (!array_key_exists($foreignKey, $keys)) {
                 $keys[$foreignKey] = $Model->field($foreignKey);
             }
             $recursive = empty($conditions) ? -1 : 0;
             $computeProp = sprintf('last%sComputation', Inflector::classify($field));
             if (isset($keys['old'][$foreignKey])) {
                 if ($keys['old'][$foreignKey] != $keys[$foreignKey]) {
                     $conditions[$fkQuoted] = $keys['old'][$foreignKey];
                     $Model->{$computeProp} = array_pop(array_pop(array_pop($Model->find('computed', compact('conditions', 'recursive')))));
                     $Model->{$parent}->updateAll(array($field => $Model->{$computeProp}), array($Model->{$parent}->escapeField() => $keys['old'][$foreignKey]));
                 }
             }
             $conditions[$fkQuoted] = $keys[$foreignKey];
             if ($recursive === 0) {
                 $conditions = array_merge($conditions, (array) $conditions);
             }
             $Model->{$computeProp} = current(current(current($Model->find('computed', compact('conditions', 'recursive')))));
             $Model->{$parent}->updateAll(array($field => $Model->{$computeProp}), array($Model->{$parent}->escapeField() => $keys[$foreignKey]));
         }
     }
 }
 /**
  * If editing or deleting a record, set the oldGroups property to the current
  * group values in the database for each group field for this model.
  *
  * @param Model $model Model object that method is triggered on
  * @return void
  */
 protected function _setOldGroups(&$model)
 {
     $this->_oldGroups[$model->alias] = null;
     $groupFields = $this->settings[$model->alias]['group_fields'];
     // If this model does not have any groups, return
     if ($groupFields === false) {
         return;
     }
     // Set oldGroups property with key of group field and current value of group
     // field from db
     foreach ($groupFields as $groupField => $escapedGroupField) {
         $this->_oldGroups[$model->alias][$groupField] = $model->field($groupField);
     }
 }
 /**
  * Checks the uniqueness of multiple fields
  *
  * Loops through the field that should be unique.
  * If a field is not present in the data array and
  * the validation is for an existing record,
  * (if an ID is present) it is tried to load the value of the field.
  * Otherwise it's considered to be empty (e.g. when adding).
  *
  * @param Model $model Model using this behavior
  * @param array $data Unused
  * @param array $fields The fields to be checked
  * @return bool True if valid, else false
  * @see Model::isUnique() Makes use of
  */
 public function multiColumnUniqueness(Model $model, $data, $fields)
 {
     if (!is_array($fields)) {
         $fields = array($fields);
     }
     $check = array();
     foreach ($fields as $key) {
         if (isset($model->data[$model->name][$key])) {
             $value = $model->data[$model->name][$key];
         } elseif (!empty($model->id)) {
             $value = $model->field($key, array($model->primaryKey => $model->id));
             if ($value === false) {
                 $value = null;
             }
         } else {
             $value = null;
         }
         $check[$key] = $value;
     }
     return $model->isUnique($check, false);
 }
Example #20
0
 /**
  * Does the actual saving of the Log model. Also adds the special field if possible.
  *
  * If model field in table, add the Model->alias
  * If action field is NOT in table, remove it from dataset
  * If the userKey field in table, add it to dataset
  * If userData is supplied to model, add it to the title
  *
  * @param Model $Model
  * @param array $logData
  * @return mixed Success
  */
 protected function _saveLog(Model $Model, $logData, $title = null)
 {
     if ($title !== null) {
         $logData['title'] = $title;
     } elseif ($Model->displayField == $Model->primaryKey) {
         $logData['title'] = $Model->alias . ' (' . $Model->id . ')';
     } elseif (!empty($Model->data[$Model->alias][$Model->displayField])) {
         $logData['title'] = $Model->data[$Model->alias][$Model->displayField];
     } elseif ($Model->id && ($title = $Model->field($Model->displayField))) {
         $logData['title'] = $title;
     } elseif (!empty($logData[$this->settings[$Model->alias]['foreignKey']])) {
         $options = array('conditions' => $logData[$this->settings[$Model->alias]['foreignKey']], 'recursive' => -1);
         $record = $Model->find('first', $options);
         if ($record) {
             $logData['title'] = $record[$Model->alias][$Model->displayField];
         }
     }
     if ($this->Log->hasField($this->settings[$Model->alias]['classField'])) {
         $logData[$this->settings[$Model->alias]['classField']] = $Model->name;
     }
     if ($this->Log->hasField($this->settings[$Model->alias]['foreignKey']) && !isset($logData[$this->settings[$Model->alias]['foreignKey']])) {
         if ($Model->id) {
             $logData[$this->settings[$Model->alias]['foreignKey']] = $Model->id;
         } elseif ($Model->insertId) {
             $logData[$this->settings[$Model->alias]['foreignKey']] = $Model->insertId;
         }
     }
     if (!$this->Log->hasField('action')) {
         unset($logData['action']);
     } elseif (isset($Model->logableAction) && !empty($Model->logableAction)) {
         $logData['action'] = implode(',', $Model->logableAction);
     }
     if ($this->Log->hasField('version_id') && isset($Model->versionId)) {
         $logData['version_id'] = $Model->versionId;
     }
     if ($this->Log->hasField('ip') && $this->userIP) {
         $logData['ip'] = $this->userIP;
     }
     if ($this->Log->hasField($this->settings[$Model->alias]['userKey']) && $this->user && isset($this->user[$this->UserModel->alias])) {
         $logData[$this->settings[$Model->alias]['userKey']] = $this->user[$this->UserModel->alias][$this->UserModel->primaryKey];
     }
     if ($this->Log->hasField('description')) {
         if (empty($logData['description'])) {
             $logData['description'] = __('Custom action');
         }
         if ($this->user && $this->UserModel && isset($this->user[$this->UserModel->alias])) {
             $logData['description'] .= ' ' . __('by') . ' ' . $this->settings[$Model->alias]['userModel'] . ' "' . $this->user[$this->UserModel->alias][$this->UserModel->displayField] . '"';
             if ($this->settings[$Model->alias]['descriptionIds']) {
                 $logData['description'] .= ' (' . $this->user[$this->UserModel->alias][$this->UserModel->primaryKey] . ')';
             }
         } else {
             // UserModel is active, but the data hasnt been set. Assume system action.
             $logData['description'] .= ' ' . __('by System');
         }
         $logData['description'] .= '.';
     }
     if (empty($logData['title'])) {
         // Fallback in case the title is null - add the action + ed
         $logData['title'] = $Model->alias . ' ' . $logData['action'] . 'ed';
     }
     $this->Log->create($logData);
     return $this->Log->save(null, array('validate' => false, 'callbacks' => false));
 }
 /**
  +----------------------------------------------------------
 * 根据表单生成查询条件
 * 进行列表过滤
  +----------------------------------------------------------
 * @access protected
  +----------------------------------------------------------
 * @param Model $model 数据对象
 * @param HashMap $map 过滤条件
 * @param string $sortBy 排序
 * @param boolean $asc 是否正序
  +----------------------------------------------------------
 * @return void
  +----------------------------------------------------------
 * @throws ThinkExecption
  +----------------------------------------------------------
 */
 protected function _list($model, $field = '*', $map = array(), $sortBy = '', $asc = false, $search = array())
 {
     session('listaction', ACTION_NAME);
     //排序字段 默认为主键名
     $pkname = $model->getPk();
     $order = !empty($sortBy) ? $sortBy : $pkname;
     //排序方式默认按照倒序排列
     //接受 sost参数 0 表示倒序 非0都 表示正序
     $sort = $asc ? $asc : 'desc';
     //取得满足条件的记录数
     $count = $model->where($map)->count($pkname);
     import("ORG.Util.Page");
     //创建分页对象
     $listRows = !empty($_REQUEST['listRows']) ? $_REQUEST['listRows'] : C('ADMIN_PAGE_SIZE');
     $p = new \Org\Util\Page($count, $listRows);
     //分页查询数据
     $list = $model->field($field)->where($map)->order($order . ' ' . $sort)->limit($p->firstRow . ',' . $p->listRows)->select();
     //分页跳转的时候保证查询条件
     foreach ($map as $key => $val) {
         if (!is_array($val)) {
             $p->parameter .= "{$key}=" . urlencode($val) . "&";
         }
     }
     foreach ($search as $key => $val) {
         if (!is_array($val)) {
             $p->parameter .= "{$key}=" . urlencode($val) . "&";
         }
     }
     if (method_exists($this, '_listFilter')) {
         $list = $this->_listFilter($list);
     }
     //分页显示
     $page = $p->show();
     //列表排序显示
     $sortImg = $sort;
     //排序图标
     $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列';
     //排序提示
     $sort = $sort == 'desc' ? 1 : 0;
     //排序方式
     //模板赋值显示
     $this->assign('list', $list);
     $this->assign("pagebar", $page);
     return;
 }
 /**
  * Log admin audit of changed object.
  *
  * @param $object
  */
 protected function logAudit(Model $object)
 {
     if (isset($object->changed_fields) && isset($object->old)) {
         foreach ($object->changed_fields as $key => $value) {
             $this->AdminUserAudit = new AdminUserAudit();
             $old_value = $object->old[$object->alias][$value];
             $new_value = $object->field($value);
             if (empty($old_value)) {
                 $old_value = 'NULL';
             }
             if (empty($new_value)) {
                 $new_value = 'NULL';
             }
             $class = get_class($object);
             $data = ['admin_user_id' => $this->admin, 'reference_name' => $class . '.id', 'reference_id' => $object->id, 'old_value' => $old_value, 'new_value' => $new_value, 'notes' => 'Admin ' . $this->admin . ' changed ' . $class . '->' . $value . ' from ' . $old_value . ' to ' . $new_value . '.'];
             CakeLog::debug($data['notes']);
             $this->AdminUserAudit->save($data);
         }
     }
 }
Example #23
0
 public function attachmentPresence(Model $model, $value)
 {
     $keys = array_keys($value);
     $field = $keys[0];
     $value = array_shift($value);
     if (!empty($value['tmp_name'])) {
         return true;
     }
     if (!empty($model->id)) {
         if (!empty($model->data[$model->alias][$field . '_file_name'])) {
             return true;
         } elseif (!isset($model->data[$model->alias][$field . '_file_name'])) {
             $existingFile = $model->field($field . '_file_name', array($model->primaryKey => $model->id));
             if (!empty($existingFile)) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Returns the previous state of the machine
  * 
  * @param	Model	$model	The model being acted on
  * @return	string			The previous state of the machine
  */
 public function getPreviousState(Model $model)
 {
     return $model->field('previous_state');
 }
Example #25
0
/**
 * 获取数据的所有子孙数据的id值
 * @author 朱亚杰 <*****@*****.**>
 */
function get_stemma($pids, Model &$model, $field = 'id')
{
    $collection = array();
    //非空判断
    if (empty($pids)) {
        return $collection;
    }
    if (is_array($pids)) {
        $pids = trim(implode(',', $pids), ',');
    }
    $result = $model->field($field)->where(array('pid' => array('IN', (string) $pids)))->select();
    $child_ids = array_column((array) $result, 'id');
    while (!empty($child_ids)) {
        $collection = array_merge($collection, $result);
        $result = $model->field($field)->where(array('pid' => array('IN', $child_ids)))->select();
        $child_ids = array_column((array) $result, 'id');
    }
    return $collection;
}
 /**
  * Get Unique ID
  *
  * @since	1.0
  * @param	Model $Model
  * @param	array $conditions Conditions array. 
  * @return	mixed False on empty. Id if found.
  */
 public function getUniqueID(Model $Model, $conditions = array())
 {
     if (empty($conditions)) {
         return false;
     }
     return $Model->field('id', array($conditions));
 }
 function beforeDelete(Model $model, $cascade = true)
 {
     foreach ($model->belongsTo as $assocKey => $assocData) {
         $this->foreignTableIDs[$assocData['className']] = $model->field($assocData['foreignKey']);
     }
     return true;
 }
Example #28
0
 /**
  * Sets the weight for new items so they end up at end
  *
  * @todo add new model with weight. clean up after
  * @param Model $Model
  */
 public function beforeSave(&$Model)
 {
     //	Check if weight id is set. If not add to end, if set update all
     // rows from ID and up
     if (!isset($Model->data[$Model->alias][$Model->primaryKey]) || isset($Model->data[$Model->alias][$this->settings[$Model->alias]['field']]) && !is_numeric($Model->data[$Model->alias][$this->settings[$Model->alias]['field']]) || $this->settings[$Model->alias]['foreign_key'] && isset($Model->data[$Model->alias][$this->settings[$Model->alias]['foreign_key']]) && $Model->data[$Model->alias][$this->settings[$Model->alias]['foreign_key']] != $Model->field($this->settings[$Model->alias]['foreign_key'])) {
         $fk = null;
         if ($this->settings[$Model->alias]['foreign_key']) {
             if (!isset($Model->data[$Model->alias][$this->settings[$Model->alias]['foreign_key']])) {
                 trigger_error('OrderedBehavior : New rows must be saved with foreign key field present.', E_USER_WARNING);
                 return false;
             }
             $fk = $Model->data[$Model->alias][$this->settings[$Model->alias]['foreign_key']];
             // foreign_key changed
             if ($fk != $Model->field($this->settings[$Model->alias]['foreign_key'])) {
                 // move down all items with old foreign_key and weight > weight of changed item
                 $conditions = array($Model->alias . '.' . $this->settings[$Model->alias]['foreign_key'] => $Model->field($this->settings[$Model->alias]['foreign_key']), $Model->alias . '.' . $this->settings[$Model->alias]['field'] . ' >' => $Model->field($this->settings[$Model->alias]['field']));
                 $Model->updateAll(array($this->settings[$Model->alias]['field'] => $Model->alias . '.' . $this->settings[$Model->alias]['field'] . ' - 1'), $conditions);
             }
         }
         $Model->data[$Model->alias][$this->settings[$Model->alias]['field']] = $this->_newWeight($Model, $fk);
     }
     return true;
 }
 /**
  * Gets the current schema version from the DB. If schema_info doesn't exist - it tries to create it.
  *
  * @access protected
  * @return int Current schema version
  */
 function _getMigrationVersion()
 {
     //load tables and see if schema_info already exists. If not, create it
     $sTables = $this->oMigrations->oDb->listSources();
     if (!in_array($this->oMigrations->oDb->config['prefix'] . 'schema_info', $sTables)) {
         $this->oMigrations->oDb->query($this->oMigrations->create_table('schema_info', array(0 => 'no_id', 1 => 'no_dates', 'version' => array('type' => 'int', 'length' => 3, 'default' => '0'))));
         //feed it with some data
         App::import('model');
         $oTemp_model = new Model(false, 'schema_info');
         $oTemp_model->saveField('version', '0');
         $this->iCurrent_version = 0;
     } else {
         App::import('model');
         $oTemp_model = new Model(false, 'schema_info');
         $this->iCurrent_version = $oTemp_model->field('version');
     }
 }
Example #30
0
<?php

if ('dbuniquecheck' == Request::get(1)) {
    $dbdate = Request::json();
    $m = new Model($dbdate[1]);
    $query_arr = array($dbdate[2] => $dbdate[4]);
    if (trim($dbdate[3]) != '') {
        $query_arr['id@<>'] = trim($dbdate[3]);
    }
    if ($m->has($query_arr)) {
        Response::write('no');
    } else {
        Response::write('ok');
    }
} elseif ('getselvt' == Request::get(1)) {
    $tn = String::decryption(Request::post('tn'));
    $aw = String::decryption(Request::post('aw'));
    $m = new Model($tn);
    $array = $m->field('id,name')->where("pid='" . Request::post('pid') . "'" . $aw)->list_all_array();
    Response::json($array);
}