public function CourseAddAction() { if (!IS_POST) { $this->error('非法请求', U('Index/index')); } $rules = array(array('course_name', 'require', '请填写课程名称', 0, '', 4), array('course_name', '0,12', '课程名称在12个字符以内', 0, 'length', 4), array('course_about', 'require', '请填写课程简介', 0, '', 4), array('course_about', '0,200', '课程名称在200个字符以内', 0, 'length', 4)); $courseModel = M('course'); $res = $courseModel->validate($rules)->create(); if (!$res) { $this->ajaxReturn(get_ajax_res(0, '添加课程失败:' . $courseModel->getError())); } $rootPath = './Uploads/Course/'; if (!is_dir($rootPath)) { mkdir($rootPath); } $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 2097152; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = $rootPath; // 设置附件上传根目录 $upload->autoSub = false; // 是否自动生成子目录 // 上传文件 $info = $upload->upload(); // 返回错误提示消息 if (!$info) { $this->ajaxReturn(get_ajax_res(0, '新增课程失败:' . $upload->getError())); } // 获取文件名和路径 $imageName = $info['course_image']['savename']; $imagePath = $rootPath . $imageName; // 将课程信息写入数据库 $courseModel->teacher_id = session('UID'); $courseModel->course_image = $imageName; $courseModel->create_time = NOW_TIME; $courseModel->teacher_name = session('truename'); $courseModel->add(); // 处理课程缩略图 $imageObject = new \Think\Image(); $imageObject->open($imagePath); $imageObject->thumb(100, 100)->save($rootPath . $imageName); // 返回成功提示 $this->ajaxReturn(get_ajax_res(1, '新增课程成功')); }
public function addHomework() { if (!IS_POST) { $this->error('非法请求', U('Index/index')); } // 添加字段 $_POST['pub_time'] = NOW_TIME; $_POST['homework_expires'] = strtotime($_POST['homework_expires']); // 动态自动验证规则 $rules = array(array('homework_name', 'require', '请填写课程作业名称', 0, '', 6), array('homework_name', '0,12', '作业名称在12个字符以内', 0, 'length', 6), array('homework_about', 'require', '请填写作业要求', 0, '', 6), array('homework_about', '0,200', '作业要求在200个字符以内', 0, 'length', 6), array('homework_expires', 'require', '请选择截止时间', 0, '', 6)); $db = M('course_homework'); // 进行自动验证 $res = $db->validate($rules)->create(); // 验证失败:返回错误信息 if (!$res) { $this->ajaxReturn(get_ajax_res(0, '添加作业失败:' . $db->getError())); } // 将作业信息添加到数据库 $res = $db->add(); // 返回成功信息 if ($res) { $this->ajaxReturn(get_ajax_res(1, '添加作业成功')); } }
public function getPassword() { if (!IS_POST) { $this->error('非法请求', U('Index/index')); } $userModel = D('user'); $res = $userModel->create($_POST, 8); if ($res) { $strObj = new \Org\Util\String(); $randString = $strObj::randString(); $map = array('username' => $userModel->username, 'email' => $userModel->email); $res = $userModel->where($map)->setField('password', md5($randString)); if ($res) { $content = '<p>系统已为您自动生成随机密码,请使用该密码登陆个人中心后进行密码更改'; $content .= '<p>您的新密码:<span class="color:red">' . $randString . '</span></p>'; $res = SendMail($userModel->email, 'Vshow重设你的密码', $content); if ($res) { $this->ajaxReturn(get_ajax_res(1, '系统已为您自动生成随机密码,请登陆邮箱查收')); } else { $this->ajaxReturn(get_ajax_res(0, '重设密码失败,请联系管理员')); } } } else { $this->ajaxReturn($userModel->getError()); } }
public function takeCourseAction() { if (!IS_POST) { $this->error('非法请求', U('Index/index')); } $courseID = I('post.courseID'); if (empty($courseID)) { $this->ajaxReturn(get_ajax_res(0, '参加课程失败:错误的操作')); } $courseStudentModel = M('courseStudent'); $map = array('course_id' => $courseID, 'user_id' => session('UID')); $res = $courseStudentModel->where($map)->find(); if ($res) { $this->ajaxReturn(get_ajax_res(0, '参加课程失败:你加入本课程')); } $data = array('course_id' => $courseID, 'user_id' => session('UID'), 'add_time' => NOW_TIME); $res = $courseStudentModel->data($data)->add(); if ($res) { $this->ajaxReturn(get_ajax_res(1, '恭喜,参加课程成功!')); } else { $this->ajaxReturn(get_ajax_res(0, '参加课程失败:请重试!')); } }
public function deleteCollect() { if (!IS_POST) { $this->error('非法请求', U('Index/index')); } $operateID = I('post.oid'); $worksID = I('post.wid'); $operationDB = M('works_operation'); $res = $operationDB->where('id = ' . $operateID)->setField('is_operate', 0); if ($res) { $countsDB = M('works_counts'); $countsMap = array('works_id' => $worksID); $countsDB->where($countsMap)->setDec('collect_counts', 1); $this->ajaxReturn(get_ajax_res(1, '取消成功')); } else { $this->ajaxReturn(get_ajax_res(0, '取消失败')); } }