/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Printer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Printer'])) { $model->attributes = $_POST['Printer']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->unused_id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate(){ $model = new Printer() ; $model->company_id = $this->companyId ; if(Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Printer'); if($model->save()) { Yii::app()->user->setFlash('success' , '添加成功'); $this->redirect(array('printer/index','companyId' => $this->companyId)); } } $this->render('create' , array( 'model' => $model , )); }
public function actionCreate() { $model = new Printer(); $model->dpid = $this->companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Printer'); $se = new Sequence("printer"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('printer/index', 'companyId' => $this->companyId)); } } $this->render('create', array('model' => $model)); }
public function add_post() { // Hook $this->HookManager->processEvent('PRINTER_ADD_POST'); // POST if ($_REQUEST['add'] != 1) { $this->FOGCore->setMessage('Printer type changed to: ' . $_REQUEST['printertype']); $this->FOGCore->redirect($this->formAction . '&printertype=' . $_REQUEST['printertype']); } if ($_REQUEST['add'] == 1) { //Remove spaces from beginning and end offields needed. $_REQUEST['alias'] = trim($_REQUEST['alias']); $_REQUEST['port'] = trim($_REQUEST['port']); $_REQUEST['inf'] = trim($_REQUEST['inf']); $_REQUEST['model'] = trim($_REQUEST['model']); $_REQUEST['ip'] = trim($_REQUEST['ip']); try { // PrinterManager $PrinterManager = $this->getClass('PrinterManager'); // Error checking if ($_REQUEST['printertype'] == "Local") { if (empty($_REQUEST['alias']) || empty($_REQUEST['port']) || empty($_REQUEST['inf']) || empty($_REQUEST['model'])) { throw new Exception('You must specify the alias, port, model, and inf. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'], 'model' => $_REQUEST['model'], 'file' => $_REQUEST['inf'], 'port' => $_REQUEST['port'], 'ip' => $_REQUEST['ip'])); } } if ($_REQUEST['printertype'] == "iPrint") { if (empty($_REQUEST['alias']) || empty($_REQUEST['port'])) { throw new Exception('You must specify the alias and port. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'], 'port' => $_REQUEST['port'])); } } if ($_REQUEST['printertype'] == "Network") { if (empty($_REQUEST['alias'])) { throw new Exception('You must specify the alias. Unable to create!'); } else { // Create new Object $Printer = new Printer(array('name' => $_REQUEST['alias'], 'config' => $_REQUEST['printertype'])); } } if ($PrinterManager->exists($_REQUEST['alias'])) { throw new Exception('Printer already exists'); } // Save if ($Printer->save()) { // Hook $this->HookManager->processEvent('PRINTER_ADD_SUCCESS', array('Printer' => &$Printer)); // Log History event $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', _('Printer created'), $Printer->get('id'), $Printer->get('name'))); //Send message to user $this->FOGCore->setMessage('Printer was created! Editing now!'); //Redirect to edit $this->FOGCore->redirect('?node=printer&sub=edit&id=' . $Printer->get('id')); } else { throw new Exception('Something went wrong. Add failed'); } } catch (Exception $e) { // Hook $this->HookManager->processEvent('PRINTER_ADD_FAIL', array('Printer' => &$Printer)); // Log History event $this->FOGCore->logHistory(sprintf('%s add failed: Name: %s, Error: %s', _('User'), $_REQUEST['name'], $e->getMessage())); // Set session message $this->FOGCore->setMessage($e->getMessage()); // Redirect user. $this->FOGCore->redirect($this->formAction); } } }