예제 #1
0
 public function lessonPostAction($cid = false, $action = 'base')
 {
     $views = $this->getView();
     $data = $this->getRequest();
     $rest = Restful::instance();
     $members = MembersManage::instance();
     $app = $members->getCurrentSession();
     $courseControl = AdminCourseManage::instance();
     $users = new AdminUserManage();
     $course = $courseControl->getCourseRow(array('course.cid' => $cid));
     $user = $category = $menus = array();
     if ($course) {
         $user = $users->getUserForId($course['uid']);
     }
     $image = new ImagesManage();
     if ($action and $tmp = explode("?", $action)) {
         $action = $tmp[0];
     }
     if ($data->isPost()) {
         switch ($action) {
             case 'base':
                 $courseControl->updateCourse($cid, $data->getPost());
                 break;
             case 'chapter':
                 $aid = $courseControl->createArticle($cid, $data->getPost());
                 break;
             case 'sort':
                 $action = 'chapter';
                 $page = $data->getQuery('page') ? $data->getQuery('page') - 1 : 0;
                 $limit = $data->getQuery('limit') ? $data->getQuery('limit') : 10;
                 $menus = $data->getPost('ids');
                 $menulist = array();
                 foreach ($menus as $key => $value) {
                     $menu_id = explode("-", $value);
                     $menulist[$key + ($page * $limit + 1)] = intval($menu_id[2]);
                 }
                 $courseControl->updateChapterSort($cid, $menulist);
                 exit;
                 break;
             case 'picture':
                 $file = $data->getFiles('picture');
                 $path = $image->save($file, $user['id'], 'tmp');
                 $scaled = getimagesize(ImagesManage::getRealPath($path));
                 if ($scaled[0] >= 1200 or $scaled[1] >= 1200) {
                     MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,图片长宽小于 1200px。');
                     ImagesManage::unlink($path);
                 } else {
                     if (!ImagesManage::hasImageType($scaled[2], true)) {
                         MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,请上传jpg, gif, png格式的文件。');
                     }
                 }
                 if ($path) {
                     header('Location: /lesson/' . $cid . '/manage/upload' . '?file=' . $path);
                     exit;
                 }
                 break;
             case 'upload':
                 $action = 'picture-crop';
                 if ($file = $data->getQuery('file')) {
                     $avatar_id = $image->saveImagesCourseFromCut($data->getQuery('file'), $data->getPost('x'), $data->getPost('y'), $data->getPost('width'), $data->getPost('height'), $user['id'], $cid, 1, true);
                     if ($avatar_id) {
                         $courseControl->updateCourse($cid, array('cover' => $avatar_id));
                         ImagesManage::unlink(ImagesManage::getRealPath($file));
                     }
                     header("Location: /lesson/{$cid}/manage/picture");
                     exit;
                 }
                 break;
             default:
                 # code...
                 break;
         }
         $course = $courseControl->getCourseRow(array('course.cid' => $cid));
     }
     switch ($action) {
         case 'base':
             $category = $courseControl->getCategory();
             $views->assign('categories', $category);
             break;
         case 'chapter':
             $page = $data->getQuery('page') ? $data->getQuery('page') : 1;
             $limit = $data->getQuery('limit') ? $data->getQuery('limit') : 10;
             $menus = $courseControl->getChapterForCID($cid, $limit, $page);
             $pages = new pagesControl("lesson/{$cid}/manage/chapter", $courseControl->getChapterCountForCID($cid), $limit, $page, true);
             $views->assign('menus', $menus);
             $views->assign('paginator', $pages);
             break;
         case 'picture':
             $courseImage = $image->getImagesCourseForCID($cid, 1);
             $coverPath = isset($courseImage['path']) ? ImagesManage::getRelativeImage($courseImage['path']) : false;
             $views->assign('image', $coverPath);
             break;
         case 'upload':
             $action = 'picture-crop';
             if ($file = $data->getQuery('file')) {
                 $views->assign('scaled', ImagesManage::getImageSizeForPath($file, 480));
                 $views->assign('file', ImagesManage::getRelativeImage($file));
             }
             break;
         default:
             # code...
             break;
     }
     $views->assign('title', '');
     $views->assign('app', $app);
     $views->assign('course', $course);
     $views->assign('user', $user);
     $views->display('index/lessonmanage/' . $action . '.html.twig');
 }
예제 #2
0
파일: Admin.php 프로젝트: dalinhuang/51mook
 public function userAvatarAction($id = false)
 {
     $views = $this->getView();
     $data = $this->getRequest();
     $members = MembersManage::instance();
     $app = $members->getCurrentSession();
     if (!$app) {
         exit;
     }
     $image = new ImagesManage();
     $userControl = new AdminUserManage();
     if ($id and $tmp = explode("?", $id)) {
         $id = $tmp[0];
     }
     $member = new AdminUserManage();
     $user = $member->getUserForId($id);
     $views->assign('user', $user);
     $views->assign('app', $app);
     if ($data->isPost()) {
         switch ($data->getQuery('action')) {
             case 'upload':
                 if ($file = $data->getQuery('file')) {
                     $avatar_id = $image->saveImagesMemberFromCut($file, $data->getPost('x'), $data->getPost('y'), $data->getPost('width'), $data->getPost('height'), $user['id'], 1, true);
                     if ($avatar_id) {
                         $userControl->updateUser($id, array('avatar_id' => $avatar_id));
                         ImagesManage::unlink(ImagesManage::getRealPath($file));
                     }
                 }
                 break;
             case 'crop':
                 $file = $data->getFiles('picture');
                 $path = $image->save($file, $user['id'], 'tmp');
                 $scaled = getimagesize(ImagesManage::getRealPath($path));
                 if ($scaled[0] >= 800 or $scaled[1] >= 800) {
                     MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,图片长宽小于 800px。');
                     ImagesManage::unlink($path);
                 } else {
                     if (!ImagesManage::hasImageType($scaled[2], true)) {
                         MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,请上传jpg, gif, png格式的文件。');
                     }
                 }
                 if ($path) {
                     header('Location: /admin/user/avatar/' . $id . '?action=upload&file=' . $path);
                     exit;
                 }
                 break;
             default:
                 # code...
                 break;
         }
     } else {
         if ($data->getQuery('action') == 'upload') {
             if ($file = $data->getQuery('file')) {
                 $views->assign('scaled', ImagesManage::getImageSizeForPath($file, 480));
                 $views->assign('file', ImagesManage::getRelativeImage($file));
                 $views->assign('tmp', $data->getQuery('file'));
                 $views->display('admin/user/user-avatar-crop-modal.html.twig');
             }
         } else {
             $memberImage = $image->getImagesMemberForID($id, 1);
             $coverPath = isset($memberImage['path']) ? ImagesManage::getRelativeImage($memberImage['path']) : false;
             $views->assign('image', $coverPath);
         }
     }
     $views->assign('title', '编辑用户头像');
     $views->display('admin/user/user-avatar-modal.html.twig');
 }
예제 #3
0
파일: Error.php 프로젝트: dalinhuang/51mook
 public function errorAction()
 {
     $views = $this->getView();
     $data = $this->getRequest();
     MessageManage::createResponse($views, '404', '404');
 }