コード例 #1
0
ファイル: CatalogController.php プロジェクト: github-zjh/task
 /**
  * 编辑
  *
  * @param  $id
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel();
     //旧文件
     $old_file = $model->attach_file;
     $old_thumb = $model->attach_thumb;
     if (isset($_POST['Catalog'])) {
         $model->attributes = $_POST['Catalog'];
         if ($_FILES['attach']['error'] == UPLOAD_ERR_OK) {
             $upload = new Uploader();
             $upload->uploadFile($_FILES['attach'], 'image', true);
             if ($upload->_error) {
                 $upload->deleteFile($upload->_file_name);
                 $upload->deleteFile($upload->_thumb_name);
                 $this->message('error', Yii::t('admin', $upload->_error));
                 return;
             }
             //删除旧文件
             $upload->deleteFile($old_file);
             $upload->deleteFile($old_thumb);
             $model->attach_file = $upload->_file_name;
             $model->attach_thumb = $upload->_thumb_name;
         }
         $model->update_time = time();
         if ($model->save()) {
             $this->message('success', Yii::t('admin', 'Update Success'), $this->createUrl('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
コード例 #2
0
ファイル: BatchAction.php プロジェクト: jerrylsxu/yiifcms
 public function run()
 {
     $ids = Yii::app()->request->getParam('id');
     $command = Yii::app()->request->getParam('command');
     empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select'));
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $ids);
     switch ($command) {
         case 'delete':
             //删除
             foreach ((array) $ids as $id) {
                 $softModel = Soft::model()->findByPk($id);
                 if ($softModel) {
                     Uploader::deleteFile(ROOT_PATH . $softModel->soft_icon);
                     Uploader::deleteFile(ROOT_PATH . $softModel->soft_file);
                 }
             }
             Soft::model()->deleteAll($criteria);
             break;
         case 'show':
             //显示
             Soft::model()->updateAll(['status' => 'Y'], $criteria);
             break;
         case 'hidden':
             //隐藏
             Soft::model()->updateAll(['status' => 'N'], $criteria);
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
     }
     $this->controller->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
コード例 #3
0
ファイル: AttachController.php プロジェクト: github-zjh/task
 /**
  * 批量操作
  * @throws CHttpException
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($this->_request->getParam('command'));
         $ids = intval($this->_request->getParam('id'));
     } elseif ($this->method() == 'POST') {
         $command = $this->_request->getPost('command');
         $ids = $this->_request->getPost('id');
     } else {
         throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'attachDelete':
             foreach ((array) $ids as $id) {
                 $uploadModel = Upload::model()->findByPk($id);
                 if ($uploadModel) {
                     Uploader::deleteFile($uploadModel->file_name);
                     $uploadModel->delete();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
コード例 #4
0
 /**
  * 修改基本资料
  * @param string $setting
  */
 public function actionSetting()
 {
     $this->_seoTitle = Yii::t('common', 'User Setting') . ' - ' . Yii::t('common', 'Setting Profile') . ' - ' . $this->_setting['site_name'];
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/jquery.Jcrop.min.css");
     $model = $this->loadModel();
     //判断账号是否已激活
     if ($this->_active_need && $model->status == -1) {
         $this->redirect($this->createUrl('activeEmail'));
     }
     $old_avatar = $model->avatar;
     if (isset($_POST['User'])) {
         $model->attributes = array_map('trim', $_POST['User']);
         //把确定上传的头像重命名
         $new_avatar = str_replace('old_', '', $model->avatar);
         @rename($model->avatar, $new_avatar);
         $model->avatar = $new_avatar;
         if ($model->save()) {
             if ($old_avatar != $model->avatar) {
                 Uploader::deleteFile($old_avatar);
             }
             //删除游离的图片
             $avatar_path = 'uploads/avatar';
             $old_files = Helper::scanfDir($avatar_path, true);
             foreach ((array) $old_files['files'] as $old) {
                 $path_parts = pathinfo($old);
                 if (!strstr($path_parts['basename'], $model->uid . '_old_')) {
                     continue;
                 }
                 Uploader::deleteFile($old);
             }
             //同步昵称
             Yii::app()->user->nickname = $model->nickname;
             //提示信息
             Yii::app()->user->setFlash('success', Yii::t('common', 'Update Profile Success'));
         }
     }
     $this->render('setting_profile', array('model' => $model));
 }
コード例 #5
0
ファイル: User.php プロジェクト: E01T/miniPHP
 /**
  * Update Profile Picture.
  *
  * @access public
  * @param  integer $userId
  * @param  array   $fileData
  * @return mixed
  * @throws Exception If failed to update profile picture.
  */
 public function updateProfilePicture($userId, $fileData)
 {
     $image = Uploader::uploadPicture($fileData, $userId);
     if (!$image) {
         $this->errors = Uploader::errors();
         return false;
     }
     $database = Database::openConnection();
     $query = "UPDATE users SET profile_picture = :profile_picture WHERE id = :id LIMIT 1";
     $database->prepare($query);
     $database->bindValue(':profile_picture', $image["basename"]);
     $database->bindValue(':id', $userId);
     $result = $database->execute();
     //if update failed, then delete the user picture
     if (!$result) {
         Uploader::deleteFile(IMAGES . "profile_pictures/" . $image["basename"]);
         throw new Exception("Profile Picture " . $image["basename"] . " couldn't be updated");
     }
     return $image;
 }
コード例 #6
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif ($this->method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
     } else {
         $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'delete':
             //删除文章
             foreach ((array) $ids as $id) {
                 $postModel = Post::model()->findByPk($id);
                 if ($postModel) {
                     $image_list = $postModel->image_list;
                     $image_list && ($image_list = unserialize($image_list));
                     if ($image_list) {
                         foreach ($image_list as $image) {
                             Uploader::deleteFile($image['file']);
                             $file = Upload::model()->findByPk($image['fileId']);
                             if ($file) {
                                 $file->delete();
                             }
                         }
                     }
                     Uploader::deleteFile($postModel->attach_file);
                     Uploader::deleteFile($postModel->attach_thumb);
                     $postModel->delete();
                     //删除关联的标签
                     TagData::model()->deleteAll('content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post']));
                 }
             }
             break;
         case 'show':
             //文章显示
             foreach ((array) $ids as $id) {
                 $postModel = Post::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->status = 'Y';
                     $postModel->save();
                     //更新关联的标签
                     $tagData = TagData::model()->updateAll(array('status' => 'Y'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post']));
                 }
             }
             break;
         case 'hidden':
             //文章隐藏
             foreach ((array) $ids as $id) {
                 $postModel = Post::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->status = 'N';
                     $postModel->save();
                     //更新关联的标签
                     $tagData = TagData::model()->updateAll(array('status' => 'N'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post']));
                 }
             }
             break;
         case 'commend':
             //文章推荐
             foreach ((array) $ids as $id) {
                 $recom_id = intval($_POST['recom_id']);
                 if ($recom_id) {
                     $postModel = Post::model()->findByPk($id);
                     if ($postModel) {
                         $postModel->commend = 'Y';
                         $postModel->save();
                         $recom_post = new RecommendPost();
                         $recom_post->id = $recom_id;
                         $recom_post->post_id = $id;
                         $recom_post->save();
                     }
                 } else {
                     $this->message('error', Yii::t('admin', 'RecommendPosition is Required'));
                 }
             }
             break;
         case 'stick':
             //文章置顶
             foreach ((array) $ids as $id) {
                 $postModel = Post::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->top_line = 'Y';
                     $postModel->save();
                 }
             }
             break;
         case 'cancelStick':
             //文章取消置顶
             foreach ((array) $ids as $id) {
                 $postModel = Post::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->top_line = 'N';
                     $postModel->save();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
コード例 #7
0
ファイル: UploadifyController.php プロジェクト: SallyU/yiicms
 /**
  * 删除附件
  * @return [type] [description]
  */
 public function actionRemove()
 {
     $imageId = intval($this->_request->getParam('imageId'));
     try {
         $imageModel = Upload::model()->findByPk($imageId);
         if ($imageModel == false) {
             throw new Exception("附件已经被删除");
         }
         Uploader::deleteFile($imageModel->file_name);
         Uploader::deleteFile($imageModel->thumb_name);
         if (!$imageModel->delete()) {
             throw new Exception("数据删除失败");
         }
         $var['state'] = 'success';
         $var['message'] = '删除完成';
     } catch (Exception $e) {
         $var['state'] = 'error';
         $var['message'] = '失败:' . $e->getMessage();
     }
     exit(CJSON::encode($var));
 }
コード例 #8
0
ファイル: VideoController.php プロジェクト: SallyU/yiicms
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif ($this->method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
     } else {
         $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'delete':
             //删除视频
             foreach ((array) $ids as $id) {
                 $postModel = Video::model()->findByPk($id);
                 if ($postModel) {
                     Uploader::deleteFile($postModel->cover_image);
                     $postModel->delete();
                 }
             }
             break;
         case 'show':
             //视频显示
             foreach ((array) $ids as $id) {
                 $postModel = Video::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->status = 'Y';
                     $postModel->save();
                 }
             }
             break;
         case 'hidden':
             //视频隐藏
             foreach ((array) $ids as $id) {
                 $postModel = Video::model()->findByPk($id);
                 if ($postModel) {
                     $postModel->status = 'N';
                     $postModel->save();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
コード例 #9
0
ファイル: Admin.php プロジェクト: reallysend/miniPHP
 /**
  * Update the backup file from the backup directory in file system
  * The user of the database MUST be assigned privilege of ADMINISTRATION -> LOCK TABLES.
  *
  * @access public
  * @return bool
  */
 public function updateBackup()
 {
     $dir = APP . "backups/";
     $files = scandir($dir);
     //delete and clean all current files in backup directory
     foreach ($files as $file) {
         if ($file != "." && $file != "..") {
             if (is_file("{$dir}/{$file}")) {
                 Uploader::deleteFile("{$dir}/{$file}");
             }
         }
     }
     //Use another username and password only for this function, while the main user has limited privileges
     $windows = true;
     if ($windows) {
         exec('C:\\wamp\\bin\\mysql\\mysql5.6.17\\bin\\mysqldump --user='******'DB_USER')) . ' --password='******'DB_PASS')) . ' ' . escapeshellcmd(Config::get('DB_NAME')) . ' > ' . APP . 'backups\\backup-' . time() . '.sql');
     } else {
         exec('mysqldump --user='******'DB_USER')) . ' --password='******'DB_PASS')) . ' ' . escapeshellcmd(Config::get('DB_NAME')) . ' > ' . APP . 'backups/backup-' . time() . '.sql');
     }
     return true;
 }
コード例 #10
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } else {
         if ($this->method() == 'POST') {
             $command = trim($_POST['command']);
             $ids = $_POST['id'];
         } else {
             $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
         }
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'adDelete':
             foreach ((array) $ids as $id) {
                 $adModel = Ad::model()->findByPk($id);
                 if ($adModel) {
                     Uploader::deleteFile($adModel->attach_file);
                     $adModel->delete();
                 }
             }
             break;
         case 'adVerify':
             foreach ((array) $ids as $id) {
                 $adModel = Ad::model()->findByPk($id);
                 if ($adModel) {
                     $adModel->status = 'Y';
                     $adModel->save();
                 }
             }
             break;
         case 'adUnVerify':
             foreach ((array) $ids as $id) {
                 $adModel = Ad::model()->findByPk($id);
                 if ($adModel) {
                     $adModel->status = 'N';
                     $adModel->save();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
コード例 #11
0
ファイル: SpecialController.php プロジェクト: SallyU/yiicms
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif ($this->method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
     } else {
         $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'specialDelete':
             foreach ((array) $ids as $id) {
                 $specialModel = Special::model()->findByPk($id);
                 if ($specialModel) {
                     Uploader::deleteFile($specialModel->attach_file);
                     Uploader::deleteFile($specialModel->attach_thumb);
                     $specialModel->delete();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
コード例 #12
0
ファイル: UserController.php プロジェクト: github-zjh/task
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($this->_request->getParam('command'));
         $ids = intval($this->_request->getParam('id'));
     } elseif ($this->method() == 'POST') {
         $command = $this->_request->getPost('command');
         $ids = $this->_request->getPost('id');
     } else {
         throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'userLock':
             foreach ((array) $ids as $id) {
                 $userModel = User::model()->findByPk($id);
                 if ($userModel) {
                     $userModel->status = 0;
                     $userModel->save();
                 }
             }
             break;
         case 'userunLock':
             foreach ((array) $ids as $id) {
                 $userModel = User::model()->findByPk($id);
                 if ($userModel) {
                     $userModel->status = 1;
                     $userModel->save();
                 }
             }
             break;
         case 'userUnpass':
             foreach ((array) $ids as $id) {
                 $userModel = User::model()->findByPk($id);
                 if ($userModel) {
                     $userModel->status = -1;
                     $userModel->save();
                 }
             }
             break;
         case 'userDelete':
             foreach ((array) $ids as $id) {
                 $userModel = User::model()->findByPk($id);
                 if ($userModel) {
                     $userModel->delete();
                     //删除绑定用户
                     OAuthQQ::model()->deleteAllByAttributes(array('uid' => $id));
                     OAuthSinawb::model()->deleteAllByAttributes(array('uid' => $id));
                     OAuthRenren::model()->deleteAllByAttributes(array('uid' => $id));
                     OAuthWeixin::model()->deleteAllByAttributes(array('uid' => $id));
                     //删除头像
                     Uploader::deleteFile($userModel->avatar);
                 }
             }
             break;
         case 'groupDelete':
             foreach ((array) $ids as $id) {
                 $groupModel = UserGroup::model()->findByPk($id);
                 if ($groupModel) {
                     $groupModel->delete();
                 }
             }
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
コード例 #13
0
ファイル: UploadifyController.php プロジェクト: uxff/myyiicms
 /**
  * 上传文件(单个不能超过50M)
  */
 public function actionFile()
 {
     if ($this->method() == 'POST') {
         $adminiUserId = Yii::app()->user->id;
         $file = new Uploader();
         $file->_allow_exts = 'pdf,doc,docx,xls,ppt,exe,zip,tar,gz,msi,7z';
         //普通文件类型限制
         $file->_allow_exts .= ',mp3,mp4,wma';
         //音频文件
         $file->_allow_exts .= ',swf,mv,avi,mp4,flv,rmvb,mov,asf,wmv,3GP,ra,rm';
         //视频文件
         $file->_rand_name = false;
         //用原来的名称
         if (is_array($_FILES['file']) && !empty($_FILES['file'])) {
             foreach ($_FILES['file'] as $value) {
                 if (is_array($value)) {
                     $files = $_FILES['file'];
                 } else {
                     $files = array($_FILES['file']);
                 }
                 break;
             }
         } else {
             exit(CJSON::encode(array('state' => 'error', 'message' => Yii::t('admin', 'Please select a file.'))));
         }
         foreach ($files as $simplefile) {
             $file->uploadFile($simplefile);
             if ($file->_error) {
                 exit(CJSON::encode(array('state' => 'error', 'message' => Yii::t('admin', $file->_error))));
             } else {
                 $model = new Upload();
                 $model->user_id = intval($adminiUserId);
                 $model->file_name = $file->_file_name;
                 $model->thumb_name = $file->_thumb_name;
                 $model->real_name = $file->_real_name;
                 $model->file_ext = $file->_file_ext;
                 $model->file_mime = $file->_mime_type;
                 $model->file_size = $file->_file_size;
                 $model->create_time = time();
                 if ($model->save()) {
                     exit(CJSON::encode(array('state' => 'success', 'realname' => $file->_real_name, 'fileId' => $model->id)));
                 } else {
                     $file->deleteFile($file->_file_name);
                     exit(CJSON::encode(array('state' => 'error', 'message' => Yii::t('admin', 'Save failed, Upload error'))));
                 }
             }
         }
     }
 }
コード例 #14
0
ファイル: File.php プロジェクト: reallysend/miniPHP
 /**
  * deletes file.
  * This method overrides the deleteById() method in Model class.
  *
  * @access public
  * @param  array    $id
  * @throws Exception If failed to delete the file
  *
  */
 public function deleteById($id)
 {
     $database = Database::openConnection();
     $database->getById("files", $id);
     $file = $database->fetchAssociative();
     //start a transaction to guarantee the file will be deleted from both; database and filesystem
     $database->beginTransaction();
     $database->deleteById("files", $id);
     if ($database->countRows() !== 1) {
         $database->rollBack();
         throw new Exception("Couldn't delete file");
     }
     $basename = $file["hashed_filename"] . "." . $file["extension"];
     Uploader::deleteFile(APP . "uploads/" . $basename);
     $database->commit();
 }
コード例 #15
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif ($this->method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
     } else {
         $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'delete':
             //删除商品
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $image_list = $goodsModel->image_list;
                     $image_list && ($image_list = unserialize($image_list));
                     if ($image_list) {
                         foreach ($image_list as $image) {
                             Uploader::deleteFile($image['file']);
                             $file = Upload::model()->findByPk($image['fileId']);
                             if ($file) {
                                 $file->delete();
                             }
                         }
                     }
                     Uploader::deleteFile($goodsModel->default_image);
                     Uploader::deleteFile($goodsModel->default_thumb);
                     $goodsModel->delete();
                 }
             }
             break;
         case 'show':
             //商品显示
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->status = 'Y';
                     $goodsModel->save();
                 }
             }
             break;
         case 'hidden':
             //商品隐藏
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->status = 'N';
                     $goodsModel->save();
                 }
             }
             break;
         case 'commend':
             //商品推荐
             foreach ((array) $ids as $id) {
                 $recom_id = intval($_POST['recom_id']);
                 if ($recom_id) {
                     $goodsModel = Goods::model()->findByPk($id);
                     if ($goodsModel) {
                         $goodsModel->recommend = 'Y';
                         $goodsModel->save();
                     }
                 } else {
                     $this->message('error', Yii::t('admin', 'RecommendPosition is Required'));
                 }
             }
             break;
         case 'unCommend':
             //商品取消推荐
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->commend = 'N';
                     $goodsModel->save();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'));
 }