Exemplo n.º 1
0
 public function actionPort_edit()
 {
     $this->setauth();
     //检查有无权限
     $db = Yii::app()->m_db;
     $id = $_GET['id'];
     $port = VcosPort::model()->findByPk($id);
     $sql = "SELECT b.id FROM vcos_port a LEFT JOIN vcos_port_language b ON a.port_id = b.port_id WHERE a.port_id = {$id} AND b.iso ='" . Yii::app()->params['language'] . "'";
     $id2 = Yii::app()->m_db->createCommand($sql)->queryRow();
     $port_language = VcosPortLanguage::model()->findByPk($id2['id']);
     $current_page = 0;
     if ($_POST) {
         $photo = '';
         $photo_iso = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'cruiseinfo_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         if (isset($_POST['language']) && $_POST['language'] != '') {
             if ($_FILES['photo_iso']['error'] != 4) {
                 $result = Helper::upload_file('photo_iso', Yii::app()->params['img_save_url'] . 'cruiseinfo_images/' . Yii::app()->params['month'], 'image', 3);
                 $photo_iso = $result['filename'];
             }
         }
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         if ($photo_iso != '') {
             //判断有无上传图片
             $photo_iso_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo_iso;
         }
         if ($photo != '') {
             //判断有无上传图片
             $photo_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
         }
         //事务处理
         $transaction = $db->beginTransaction();
         try {
             if (isset($_POST['language']) && $_POST['language'] != '') {
                 //编辑系统语言和外语状态下
                 //编辑主表
                 $db->createCommand()->update('vcos_port', array('port_state' => $state), 'port_id = :id', array(':id' => $id));
                 //编辑系统语言
                 $port_columns = array('port_name' => $_POST['title'], 'describe' => $_POST['desc']);
                 if ($photo) {
                     //判断有无上传图片
                     $port_columns['img_url'] = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 //编辑系统语言
                 $db->createCommand()->update('vcos_port_language', $port_columns, 'id=:id', array(':id' => $id2['id']));
                 //判断外语是新增OR编辑
                 if ($_POST['judge'] == 'add') {
                     //新增外语
                     $db->createCommand()->insert('vcos_port_language', array('port_id' => $id, 'iso' => $_POST['language'], 'port_name' => $_POST['title_iso'], 'img_url' => $photo_iso_url, 'describe' => $_POST['desc_iso']));
                 } else {
                     //编辑外语
                     $columns = array('port_name' => $_POST['title_iso'], 'describe' => $_POST['desc_iso']);
                     if ($photo_iso != '') {
                         //判断有无上传图片
                         $columns['img_url'] = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo_iso;
                     }
                     $db->createCommand()->update('vcos_port_language', $columns, 'id=:id', array(':id' => $_POST['judge']));
                 }
                 //事务提交
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Cruiseinfo/port"));
             } else {
                 //只编辑系统语言状态下
                 $port->port_id = $id;
                 $port->port_state = $state;
                 $port->save();
                 $port_language->id = $id2['id'];
                 $port_language->port_name = $_POST['title'];
                 $port_language->describe = $_POST['desc'];
                 if ($photo) {
                     //判断有无上传图片
                     $port_language->img_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 //$port_language->img_url = $photo_url;
                 $port_language->save();
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Cruiseinfo/port"));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     }
     if (isset($_GET['page'])) {
         $current_page = 1;
     }
     $count_sql = "SELECT count(*) count FROM vcos_port_detail a, vcos_port_detail_language b, vcos_port c, vcos_port_language d WHERE a.detail_id = b.detail_id AND a.port_id = c.port_id AND a.port_id = d.port_id AND b.iso = '" . Yii::app()->language . "' AND d.iso = '" . Yii::app()->language . "'  AND a.port_id='" . $id . "' ORDER BY a.detail_id DESC";
     $count = $db->createCommand($count_sql)->queryRow();
     //分页
     $criteria = new CDbCriteria();
     $count = $count['count'];
     $pager = new CPagination($count);
     $pager->pageSize = 10;
     $pager->applyLimit($criteria);
     $sql = "SELECT * FROM vcos_port_detail a, vcos_port_detail_language b, vcos_port c, vcos_port_language d WHERE a.detail_id = b.detail_id AND a.port_id = c.port_id AND a.port_id = d.port_id AND b.iso = '" . Yii::app()->language . "' AND d.iso = '" . Yii::app()->language . "' AND a.port_id='" . $id . "' ORDER BY a.detail_id DESC LIMIT {$criteria->offset}, {$pager->pageSize}";
     $detail = $db->createCommand($sql)->queryAll();
     $this->render('port_edit', array('current_page' => $current_page, 'port' => $port, 'port_language' => $port_language, 'pages' => $pager, 'auth' => $this->auth, 'detail' => $detail));
 }
Exemplo n.º 2
0
 public function actionPort_edit()
 {
     $this->setauth();
     //检查有无权限
     $id = $_GET['id'];
     $port = VcosPort::model()->findByPk($id);
     $sql = "SELECT b.id FROM vcos_port a LEFT JOIN vcos_port_language b ON a.port_id = b.port_id WHERE a.port_id = {$id} AND b.iso ='" . Yii::app()->params['language'] . "'";
     $id2 = Yii::app()->m_db->createCommand($sql)->queryRow();
     $port_language = VcosPortLanguage::model()->findByPk($id2['id']);
     if ($_POST) {
         $photo = '';
         $photo_iso = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'cruiseinfo_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         if (isset($_POST['language']) && $_POST['language'] != '') {
             if ($_FILES['photo_iso']['error'] != 4) {
                 $result = Helper::upload_file('photo_iso', Yii::app()->params['img_save_url'] . 'cruiseinfo_images/' . Yii::app()->params['month'], 'image', 3);
                 $photo_iso = $result['filename'];
             }
         }
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         if ($photo_iso != '') {
             //判断有无上传图片
             $photo_iso_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo_iso;
         }
         if ($photo != '') {
             //判断有无上传图片
             $photo_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
         }
         //事务处理
         $db = Yii::app()->m_db;
         $transaction = $db->beginTransaction();
         try {
             if (isset($_POST['language']) && $_POST['language'] != '') {
                 //编辑系统语言和外语状态下
                 //编辑主表
                 $db->createCommand()->update('vcos_port', array('port_state' => $state), 'port_id = :id', array(':id' => $id));
                 //编辑系统语言
                 $port_columns = array('port_name' => $_POST['title'], 'describe' => $_POST['desc']);
                 if ($photo) {
                     //判断有无上传图片
                     $port_columns['img_url'] = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 //编辑系统语言
                 $db->createCommand()->update('vcos_port_language', $port_columns, 'id=:id', array(':id' => $id2['id']));
                 //判断外语是新增OR编辑
                 if ($_POST['judge'] == 'add') {
                     //新增外语
                     $db->createCommand()->insert('vcos_port_language', array('port_id' => $id, 'iso' => $_POST['language'], 'port_name' => $_POST['title_iso'], 'img_url' => $photo_iso_url, 'describe' => $_POST['desc_iso']));
                 } else {
                     //编辑外语
                     $columns = array('port_name' => $_POST['title_iso'], 'describe' => $_POST['desc_iso']);
                     if ($photo_iso != '') {
                         //判断有无上传图片
                         $columns['img_url'] = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo_iso;
                     }
                     $db->createCommand()->update('vcos_port_language', $columns, 'id=:id', array(':id' => $_POST['judge']));
                 }
                 //事务提交
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Cruiseinfo/port"));
             } else {
                 //只编辑系统语言状态下
                 $port->port_id = $id;
                 $port->port_state = $state;
                 $port->save();
                 $port_language->id = $id2['id'];
                 $port_language->port_name = $_POST['title'];
                 $port_language->describe = $_POST['desc'];
                 if ($photo) {
                     //判断有无上传图片
                     $port_language->img_url = 'cruiseinfo_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 //$port_language->img_url = $photo_url;
                 $port_language->save();
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Cruiseinfo/port"));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     }
     $this->render('port_edit', array('port' => $port, 'port_language' => $port_language));
 }