/** * Update a product. * * @param int $productID * @access public * @return void */ public function update($productID) { $oldProduct = $this->getByID($productID); $product = fixer::input('post')->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->get(); $this->dao->update(TABLE_PRODUCT)->data($product)->autoCheck()->batchCheck($this->config->product->require->edit, 'notempty')->where('id')->eq($productID)->exec(); if (dao::isError()) { return false; } return commonModel::createChanges($oldProduct, $product); }
/** * Update a balance. * * @param int $balanceID * @access public * @return string|bool */ public function update($balanceID) { $oldBalance = $this->getByID($balanceID); $depositor = $this->loadModel('depositor')->getByID($this->post->depositor); $balance = fixer::input('post')->add('currency', $depositor->currency)->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->removeIF($this->post->type == 'cash', 'public')->get(); $this->dao->delete()->from(TABLE_BALANCE)->where('depositor')->eq($balance->depositor)->andWhere('date')->eq($balance->date)->andWhere('id')->ne($balanceID)->exec(); $this->dao->update(TABLE_BALANCE)->data($balance)->autoCheck()->where('id')->eq($balanceID)->exec(); if (!dao::isError()) { return commonModel::createChanges($oldBalance, $balance); } return false; }
/** * Update a doc. * * @param int $docID * @access public * @return void */ public function update($docID) { $oldDoc = $this->getById($docID); $doc = fixer::input('post')->cleanInt('module')->setDefault('module', 0)->specialChars('title, digest, keywords')->encodeURL('url')->stripTags('content', $this->config->allowedTags->admin)->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->remove('comment,files,labels')->get(); $uniqueCondition = "lib = '{$oldDoc->lib}' AND module = {$doc->module} AND id != {$docID}"; $doc = $this->loadModel('file')->processEditor($doc, $this->config->doc->editor->edit['id']); $this->dao->update(TABLE_DOC)->data($doc, 'uid')->autoCheck()->batchCheck($this->config->doc->require->edit, 'notempty')->check('title', 'unique', $uniqueCondition)->where('id')->eq((int) $docID)->exec(); if (!dao::isError()) { return commonModel::createChanges($oldDoc, $doc); } }
/** * Update a customer. * * @param int $customerID * @access public * @return array */ public function update($customerID) { $oldCustomer = $this->getByID($customerID); $customer = fixer::input('post')->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->setIF(!$this->post->public and $oldCustomer->relation == 'client', 'public', 0)->stripTags('desc', $this->config->allowedTags->admin)->get(); /* Add http:// in head when that has not http:// or https://. */ if (strpos($customer->site, '://') === false) { $customer->site = 'http://' . $customer->site; } if (strpos($customer->weibo, 'http://weibo.com/') === false) { $customer->weibo = 'http://weibo.com/' . $customer->weibo; } if ($customer->site == 'http://') { $customer->site = ''; } if ($customer->weibo == 'http://weibo.com/') { $customer->weibo = ''; } $customer = $this->loadModel('file')->processEditor($customer, $this->config->customer->editor->edit['id']); $this->dao->update(TABLE_CUSTOMER)->data($customer, $skip = 'uid')->autoCheck()->batchCheck($this->config->customer->require->edit, 'notempty')->where('id')->eq($customerID)->exec(); if (dao::isError()) { return array('result' => 'fail', 'message' => dao::getError()); } $changes = commonModel::createChanges($oldCustomer, $customer); if ($changes) { $actionID = $this->loadModel('action')->create('customer', $customerID, 'Edited'); $this->action->logHistory($actionID, $changes); } $locate = strpos($this->server->http_referer, 'provider') ? helper::createLink('provider', 'view', "customerID={$customerID}") : helper::createLink('customer', 'view', "customerID={$customerID}"); return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate); }
/** * Edit return. * * @param object $return * @access public * @return bool */ public function editReturn($return, $purchase) { $now = helper::now(); $data = fixer::input('post')->add('contract', $purchase->id)->setDefault('returnedBy', $this->app->user->account)->setDefault('returnedDate', $now)->remove('finish,handlers')->get(); $this->dao->update(TABLE_PLAN)->data($data, $skip = 'uid, comment')->where('id')->eq($return->id)->autoCheck()->batchCheck($this->config->purchase->require->receive, 'notempty')->exec(); if (!dao::isError()) { $changes = commonModel::createChanges($return, $data); if ($changes) { $actionID = $this->loadModel('action')->create('contract', $purchase->id, 'editReturned'); $this->action->logHistory($actionID, $changes); } $returnList = $this->getReturnList($return->contract, 'returnedDate_desc'); $purchaseData = new stdclass(); $purchaseData->return = 'doing'; $purchaseData->editedBy = $this->app->user->account; $purchaseData->editedDate = $now; $purchaseData->handlers = implode(',', $this->post->handlers); $purchaseData->returnedBy = current($returnList)->returnedBy; $purchaseData->returnedDate = current($returnList)->returnedDate; if ($this->post->finish) { $purchaseData->return = 'done'; } $this->dao->update(TABLE_CONTRACT)->data($purchaseData, $skip = 'uid, comment')->where('id')->eq($purchase->id)->exec(); if (!dao::isError() and $this->post->finish) { $this->dao->update(TABLE_CUSTOMER)->set('status')->eq('payed')->where('id')->eq($purchase->customer)->exec(); } return !dao::isError(); } return false; }
/** * Update a trade. * * @param int $tradeID * @access public * @return string|bool */ public function update($tradeID) { $oldTrade = $this->getByID($tradeID); if ($oldTrade->type == 'in') { $_POST['objectType'] = array('contract'); } $trade = fixer::input('post')->add('type', $oldTrade->type)->setDefault('contract', 0)->setIf(!$this->post->objectType or !in_array('order', $this->post->objectType), 'order', 0)->setIf(!$this->post->objectType or !in_array('contract', $this->post->objectType), 'contract', 0)->setIf(!$this->post->trader, 'trader', 0)->add('handlers', trim(join(',', $this->post->handlers), ','))->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->remove('objectType')->striptags('desc')->get(); $this->dao->update(TABLE_TRADE)->data($trade, $skip = 'createTrader,traderName')->autoCheck()->batchCheck($this->config->trade->require->edit, 'notempty')->where('id')->eq($tradeID)->exec(); if ($this->post->createTrader and $trade->type == 'out') { $trader = new stdclass(); $trader->relation = 'provider'; $trader->name = $this->post->traderName; $trader->public = 1; $this->dao->insert(TABLE_CUSTOMER)->data($trader)->check('name', 'notempty')->exec(); $traderID = $this->dao->lastInsertID(); $this->loadModel('action')->create('customer', $traderID, 'Created'); $this->dao->update(TABLE_TRADE)->set('trader')->eq($traderID)->where('id')->eq($tradeID)->exec(); } if (!dao::isError()) { return commonModel::createChanges($oldTrade, $trade); } return false; }
/** * Close task. * * @param int $taskID * @access public * @return array */ public function close($taskID) { $oldTask = $this->getById($taskID); $now = helper::now(); $task = fixer::input('post')->setDefault('status', 'closed')->setDefault('assignedTo', 'closed')->setDefault('assignedDate', $now)->setDefault('closedBy, editedBy', $this->app->user->account)->setDefault('closedDate, editedDate', $now)->setIF($oldTask->status == 'done', 'closedReason', 'done')->setIF($oldTask->status == 'cancel', 'closedReason', 'cancel')->remove('taskIDList')->get(); $this->dao->update(TABLE_TASK)->data($task, 'uid,comment')->autoCheck()->where('id')->eq((int) $taskID)->exec(); $this->updateParent($oldTask); if (!dao::isError()) { return commonModel::createChanges($oldTask, $task); } }
/** * Update project's members. * * @param int $projectID * @access public * @return array */ public function updateMembers($projectID) { $oldProject = $this->getById($projectID); $members = array(); $project = new stdclass(); /* Delete old member. */ $this->dao->delete()->from(TABLE_TEAM)->where('type')->eq('project')->andWhere('id')->eq($projectID)->andWhere('role')->ne('manager')->exec(); /* save new members. */ if (!empty($_POST['member'])) { foreach ($this->post->member as $key => $account) { if (empty($account)) { continue; } $member = new stdclass(); $member->type = 'project'; $member->id = $projectID; $member->account = $account; $member->role = $this->post->role[$key]; $this->dao->insert(TABLE_TEAM)->data($member)->autoCheck()->exec(); $members[$account] = $member; } } $project->members = $members; return commonModel::createChanges($oldProject, $project); }
/** * Update address. * * @param int $addressID * @access public * @return string */ public function update($addressID) { $oldAddress = $this->getByID($addressID); $address = fixer::input('post')->get(); $this->dao->update(TABLE_ADDRESS)->data($address)->where('id')->eq($addressID)->exec(); if (dao::isError()) { return false; } return commonModel::createChanges($oldAddress, $address); }
/** * Assign to. * * @param int $todoID * @access public * @return array|bool */ public function assignTo($todoID) { $oldTodo = $this->getById($todoID); $todo = fixer::input('post')->remove('account')->add('assignedBy', $this->app->user->account)->add('assignedDate', helper::now())->get(); $this->dao->update(TABLE_TODO)->data($todo)->autoCheck()->where('id')->eq($todoID)->exec(); if (!dao::isError()) { return commonModel::createChanges($oldTodo, $todo); } return false; }
/** * Update a depositor. * * @param int $depositorID * @access public * @return string|bool */ public function update($depositorID) { $oldDepositor = $this->getByID($depositorID); $depositor = fixer::input('post')->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->removeIF($this->post->type == 'cash', 'public')->get(); $depositor->tags = trim(str_replace(',', ',', $depositor->tags), ','); $this->dao->update(TABLE_DEPOSITOR)->data($depositor)->autoCheck()->batchCheck($this->config->depositor->require->edit, 'notempty')->where('id')->eq($depositorID)->exec(); if (!dao::isError()) { return commonModel::createChanges($oldDepositor, $depositor); } return false; }
/** * Update an order. * * @param int $orderID * @access public * @return void */ public function update($orderID) { $oldOrder = $this->getByID($orderID); $now = helper::now(); $order = fixer::input('post')->setDefault('nextDate', '0000-00-00')->setDefault('signedDate', '0000-00-00')->setDefault('closedDate', '0000-00-00 00:00:00')->join('product', ',')->setIF($this->post->signedBy, 'status', 'signed')->setIF($this->post->closedBy, 'status', 'closed')->setIF($this->post->status == 'closed' and !$this->post->closedBy, 'closedBy', $this->app->user->account)->setIF($this->post->status == 'closed' and !$this->post->closedDate, 'closedDate', $now)->setIF($this->post->status == 'signed' and !$this->post->signedBy, 'signedBy', $this->app->user->account)->setIF($this->post->status == 'signed' and !$this->post->signedDate, 'signedDate', substr($now, 0, 10))->add('editedBy', $this->app->user->account)->add('editedDate', $now)->get(); $order->product = $order->product ? ',' . $order->product . ',' : ''; $this->dao->update(TABLE_ORDER)->data($order, $skip = 'referer')->autoCheck()->batchCheck($this->config->order->require->edit, 'notempty')->where('id')->eq($orderID)->exec(); if (dao::isError()) { return false; } return commonModel::createChanges($oldOrder, $order); }
/** * leave * * @param int $resumeID * @access public * @return void */ public function leave($resumeID) { $oldResume = $this->getByID($resumeID); $resume = new stdclass(); $resume->left = helper::today(); $this->dao->update(TABLE_RESUME)->data($resume)->where('id')->eq($resumeID)->exec(); /* Update contact info if exists another same resume. */ $sameResume = $this->dao->select('id')->from(TABLE_RESUME)->where('contact')->eq($oldResume->contact)->andWhere('customer')->eq($oldResume->customer)->andWhere('`left`')->eq('')->orWhere('contact')->eq($oldResume->contact)->andWhere('customer')->eq($oldResume->customer)->andWhere('`left`')->gt(helper::today())->fetch('id'); if ($sameResume) { $this->dao->update(TABLE_CONTACT)->set('resume')->eq($sameResume)->exec(); } return commonModel::createChanges($oldResume, $resume); }
/** * Update schema. * * @param int $schemaID * @access public * @return array */ public function update($schemaID) { $oldSchema = $this->getByID($schemaID); $schema = fixer::input('post')->setIF($this->post->feeRow, 'fee', '')->setIF($this->post->diffCol, 'money', "{$this->post->in},{$this->post->out}")->remove('feeRow,diffCol')->get(); if ($this->post->diffCol) { $this->config->schema->require->edit = str_replace(',type,', ',in,out,', $this->config->schema->require->edit); } $this->dao->update(TABLE_SCHEMA)->data($schema, 'in,out')->autoCheck()->batchCheck($this->config->schema->require->edit, 'notempty')->where('id')->eq($schemaID)->exec(); if (!dao::isError()) { return commonModel::createChanges($oldSchema, $schema); } return false; }
/** * update a refund. * * @param int $refundID * @access public * @return object|bool */ public function update($refundID) { $oldRefund = $this->getByID($refundID); $refund = fixer::input('post')->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->setDefault('date', helper::today())->join('related', ',')->remove('status,firstReviewer,firstReviewDate,sencondReviewer,secondReviewDate,refundBy,refundDate,files,labels')->remove('idList,dateList,moneyList,currencyList,categoryList,descList,relatedList')->get(); $this->dao->update(TABLE_REFUND)->data($refund)->autoCheck()->batchCheck($this->config->refund->require->edit, 'notempty')->where('id')->eq($refundID)->exec(); /* update details. */ if (!empty($_POST['moneyList'])) { $newDetails = array(); foreach ($this->post->moneyList as $key => $money) { if (empty($money)) { continue; } $detail = new stdclass(); $detail->id = empty($_POST['idList'][$key]) ? '0' : $_POST['idList'][$key]; $detail->parent = $refundID; $detail->status = 'wait'; $detail->createdBy = $this->app->user->account; $detail->createdDate = helper::now(); $detail->money = $money; $detail->date = empty($_POST['dateList'][$key]) ? $refund->date : $_POST['dateList'][$key]; $detail->currency = $refund->currency; $detail->category = $_POST['categoryList'][$key]; $detail->desc = $_POST['descList'][$key]; if ($detail->id == '0') { $this->dao->insert(TABLE_REFUND)->data($detail, 'id')->autoCheck()->exec(); $detail->id = $this->dao->lastInsertID(); } else { $this->dao->update(TABLE_REFUND)->data($detail, 'id,createdBy,createdDate')->autoCheck()->where('id')->eq($detail->id)->exec(); } $newDetails[$detail->id] = $detail; } $refund->detail = $newDetails; /* remove old details. */ foreach ($oldRefund->detail as $detail) { if (!isset($newDetails[$detail->id])) { $this->dao->delete()->from(TABLE_REFUND)->where('id')->eq($detail->id)->exec(); } } } else { /* remove old details. */ foreach ($oldRefund->detail as $detail) { $this->dao->delete()->from(TABLE_REFUND)->where('id')->eq($detail->id)->exec(); } } return commonModel::createChanges($oldRefund, $refund); }