/** * 新建模板 * @author yongze */ public function actionCreate($id) { $dsModel = $this->loadModel((int) $id, 'ds'); $dbModel = $this->loadModel((int) $dsModel->database_id, 'db'); $model = new Template('Create'); $data = array(); if (isset($_POST['Template'])) { if (isset($_POST['Template']['type'])) { $_POST['Template']['type'] = (int) $_POST['Template']['type']; } $model->attributes = $_POST['Template']; $model->dataset_id = (int) $dsModel->id; $model->dataset_name = $dsModel->name; if ($model->save()) { $this->addLog('template', $model->id, '添加新模板“' . $model->tpname . '”'); Yii::app()->user->setFlash("success", "新建 <b>{$model->tpname}</b> 模板成功!"); } else { $errorMsg = ''; $errorErr = $model->getErrors(); foreach ($errorErr as $value) { $errorMsg .= "\t" . $value[0]; } $errorMsg = trim($errorMsg, ','); Yii::app()->user->setFlash("error", $errorMsg); } $this->redirect(array('/Template/Index/' . $dsModel->id)); } $data['dbModel'] = $dbModel; $data['dsModel'] = $dsModel; $data['model'] = $model; $data['datasetId'] = $id; $this->_getFieldsInfos($data['_txtfiled'], $id); $this->render('edit', $data); }
function deleteAction() { $id = AF::get($_POST, 'id', 0); $modelsID = explode(',', $id); $errors = FALSE; foreach ($modelsID as $id) { $model = new Template(); $model->model_uset_id = $this->user->user_id; if ($model->fillFromDbPk($id)) { $model->delete($id); } else { $errors = TRUE; } if ($model->getErrors()) { $errors = TRUE; } unset($model); } if (isset($_POST['ajax'])) { AF::setJsonHeaders('json'); if ($errors) { Message::echoJsonError(__('template_not_deleted')); } else { $countE = AF::get($_POST, 'countE', 100000); if (count($modelsID) >= $countE) { $link = AF::link(array('templates' => 'view')); Message::echoJsonRedirect($link); } else { Message::echoJsonSuccess(__('template_deleted')); } } } $this->redirect(); }
/** * @return array Errors Import Template information */ public static function importTemplates($root, $companyId, &$errors) { $nodeTemplates = $root->getElementsByTagName('template'); foreach ($nodeTemplates as $nodeTemplate) { if ($root->getAttribute('version') > 1.0) { $errors[] = '*TemplateVersion*' . Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version'); $errors[] = Yii::t('lazy8', 'Select a file and try again'); } $modelTemplate = new Template(); $modelTemplate->companyId = $companyId; $modelTemplate->name = $nodeTemplate->getAttribute('name'); $modelTemplate->desc = $nodeTemplate->getAttribute('desc'); $modelTemplate->sortOrder = $nodeTemplate->getAttribute('sortorder'); $modelTemplate->allowAccountingView = $nodeTemplate->getAttribute('allowaccountingview') == '1' ? 1 : 0; $modelTemplate->allowFreeTextField = $nodeTemplate->getAttribute('allowfreetextfield') == '1' ? 1 : 0; $modelTemplate->freeTextFieldDefault = $nodeTemplate->getAttribute('freetextfielddefault'); $modelTemplate->allowFilingTextField = $nodeTemplate->getAttribute('allowfilingtextfield') == '1' ? 1 : 0; $modelTemplate->filingTextFieldDefault = $nodeTemplate->getAttribute('filingtextfielddefault'); $modelTemplate->forceDateToday = $nodeTemplate->getAttribute('forcedatetoday'); if (!$modelTemplate->save()) { $errors[] = Yii::t('lazy8', 'Could not create the modelTemplate, bad paramters') . ';name=' . $modelTemplate->name . ';' . serialize($modelTemplate->getErrors()); return $errors; } $nodesTemplateRows = $nodeTemplate->getElementsByTagName('templaterow'); foreach ($nodesTemplateRows as $nodesTemplateRow) { $modelTemplateRow = new TemplateRow(); $modelTemplateRow->templateId = $modelTemplate->id; $modelTemplateRow->name = $nodesTemplateRow->getAttribute('name'); $modelTemplateRow->desc = $nodesTemplateRow->getAttribute('desc'); $modelTemplateRow->sortOrder = $nodesTemplateRow->getAttribute('sortorder'); $modelTemplateRow->isDebit = $nodesTemplateRow->getAttribute('isdebit') == '1' ? 1 : 0; $modelTemplateRow->defaultAccountId = Template::FindAccountId($nodesTemplateRow->getAttribute('defaultaccount'), $modelTemplate->companyId); $modelTemplateRow->defaultValue = $nodesTemplateRow->getAttribute('defaultvalue'); $modelTemplateRow->allowMinus = $nodesTemplateRow->getAttribute('allowminus') == '1' ? 1 : 0; $modelTemplateRow->phpFieldCalc = $nodesTemplateRow->getAttribute('phpfieldcalc'); $modelTemplateRow->allowChangeValue = $nodesTemplateRow->getAttribute('allowchangevalue') == '1' ? 1 : 0; $modelTemplateRow->allowRepeatThisRow = $nodesTemplateRow->getAttribute('allowrepeatthisrow') == '1' ? 1 : 0; $modelTemplateRow->allowCustomer = $nodesTemplateRow->getAttribute('allowcustomer') == '1' ? 1 : 0; $modelTemplateRow->allowNotes = $nodesTemplateRow->getAttribute('allownotes') == '1' ? 1 : 0; $modelTemplateRow->isFinalBalance = $nodesTemplateRow->getAttribute('isfinalbalance') == '1' ? 1 : 0; if (!$modelTemplateRow->save()) { $modelTemplate->delete(); $errors[] = Yii::t('lazy8', 'Could not create the TemplateRow, bad paramters') . ';' . serialize($modelTemplateRow->getErrors()); return; } $nodesTemplateRowAccounts = $nodesTemplateRow->getElementsByTagName('templaterowaccount'); foreach ($nodesTemplateRowAccounts as $nodesTemplateRowAccount) { $modelTemplateRowAccount = new TemplateRowAccount(); $modelTemplateRowAccount->templateRowId = $modelTemplateRow->id; $modelTemplateRowAccount->accountId = Template::FindAccountId($nodesTemplateRowAccount->getAttribute('code'), $modelTemplate->companyId); if ($modelTemplateRowAccount->accountId != 0) { if (!$modelTemplateRowAccount->save()) { $modelTemplate->delete(); $errors[] = Yii::t('lazy8', 'Could not create the TemplateRowAccount, bad paramters') . ';' . serialize($modelTemplateRowAccount->getErrors()); return; } } else { $errors[] = Yii::t('lazy8', 'Could not create the Account, bad account number') . ';' . $nodesTemplateRowAccount->getAttribute('code'); } } } } }