public function index() { StudentModel::studentAjaxLogout(); redirect('student/profile/basic'); }
public function logout() { StudentModel::studentAjaxLogout(); message('退出成功!', "student/index/login", 'success'); }
public function logoutFunc($url = NULL) { return StudentModel::studentAjaxLogout($url); }
public function awards_save() { $uid = $this->_uinfo['uid']; if (empty($_POST)) { redirect('student/profile/awards'); } if ($uid) { $student = StudentModel::get_student($uid); if (empty($student)) { StudentModel::studentAjaxLogout(); redirect('student/index/login'); } } else { $student = $this->session->userdata('student'); if (empty($student)) { redirect('student/practice/basic'); } } $message = array(); //---------------------------------------------------// // 年级排名 //---------------------------------------------------// // 数据初始化 $score_ranking = array(); $score_rank_arr = $this->input->post('score_rank'); if (!isset($score_rank_arr['grade_id']) or !is_array($score_rank_arr['grade_id'])) { $score_rank_arr['grade_id'] = array(); } // 整理数据 foreach ($score_rank_arr['grade_id'] as $k => $v) { $rank['grade_id'] = abs(intval($v)); $rank['ranking'] = isset($score_rank_arr['ranking'][$k]) ? abs(intval($score_rank_arr['ranking'][$k])) : 0; $rank['totalnum'] = isset($score_rank_arr['totalnum'][$k]) ? abs(intval($score_rank_arr['totalnum'][$k])) : 0; // 无效数据,跳过 if (empty($rank['grade_id']) or empty($rank['ranking']) or empty($rank['totalnum']) or $rank['grade_id'] > $student['grade_id'] or $rank['ranking'] > $rank['totalnum']) { continue; } $score_ranking[$rank['grade_id']] = $rank; } // 检查是否完整填写 if ($student['grade_id'] > 1 && empty($score_ranking)) { $message[] = '请填写年级排名'; } else { $start_grade = $student['grade_id'] < 3 ? 1 : $student['grade_id'] - 1; for ($i = $student['grade_id']; $i >= $start_grade; $i--) { if (!isset($score_ranking[$i])) { $message[] = '请填写最近三年年级成绩排名' . $start_grade; break; } } } if ($message) { message(implode('<br/>', $message)); } //---------------------------------------------------// // 获奖情况 //---------------------------------------------------// $awards_list = array(); $awards_subject_arr = (array) $this->input->post('awards_subject'); $awards_awards_arr = $this->input->post('awards_awards'); $awards_grade_arr = $this->input->post('awards_grade'); $awards_ids_arr = $this->input->post('awards_ids'); foreach ($awards_subject_arr as $type_id => $subject_arr) { if (empty($type_id) or !is_array($subject_arr)) { continue; } $awards_arr = isset($awards_awards_arr[$type_id]) ? $awards_awards_arr[$type_id] : array(); $grade_arr = isset($awards_grade_arr[$type_id]) ? $awards_grade_arr[$type_id] : array(); $ids_arr = isset($awards_ids_arr[$type_id]) ? $awards_ids_arr[$type_id] : array(); foreach ($subject_arr as $k => $v) { $awards = array('id' => isset($ids_arr[$k]) ? intval($ids_arr[$k]) : 0, 'uid' => 0, 'typeid' => $type_id, 'subject' => intval($v), 'awards' => isset($awards_arr[$k]) ? intval($awards_arr[$k]) : 0, 'grade' => isset($grade_arr[$k]) ? intval($grade_arr[$k]) : 0, 'other_name' => '', 'other_desc' => ''); if (empty($awards['subject']) or empty($awards['awards']) or empty($awards['grade']) or $awards['grade'] <= 12 && $awards['grade'] > $student['grade_id']) { continue; } $awards_list[$type_id][] = $awards; } } //---------------------------------------------------// // 其他获奖情况 //---------------------------------------------------// $awards_other = $this->input->post('awards_other', TRUE); if (!isset($awards_other['name']) or !is_array($awards_other['name'])) { $awards_other['name'] = array(); } foreach ($awards_other['name'] as $k => $other_name) { $other_name = trim($other_name); $other_id = isset($awards_other['id'][$k]) ? intval($awards_other['id'][$k]) : 0; $other_desc = isset($awards_other['desc'][$k]) ? trim($awards_other['desc'][$k]) : ''; if (empty($other_name) or empty($other_desc)) { continue; } $awards = array('id' => $other_id, 'uid' => 0, 'typeid' => 0, 'subject' => 0, 'awards' => 0, 'grade' => 0, 'other_name' => $other_name, 'other_desc' => $other_desc); $awards_list[0][] = html_escape($awards); } $school_id_arr = $this->input->post('school_id'); $volunteer_arr = $this->input->post('volunteer'); if (empty($volunteer_arr[a])) { $school_id_arr[a] = ''; } if (intval($school_id_arr[a]) == 0) { message('第一志愿不能为空'); } if (empty($volunteer_arr[b])) { $school_id_arr[b] = ''; } if (empty($volunteer_arr[c])) { $school_id_arr[c] = ''; } $volunteer = json_encode($school_id_arr); //将升学志愿学校id转换为json值 //选考学考 //$is_in_class = $this->input->post('is_in_class'); //$subject_class = serialize(/* array_filter*/ ( $this->input->post('subject_class') ) ); //$subject_in = serialize( /*array_filter */( $this->input->post('subject_in') ) ); //$subject_not = serialize( /*array_filter */( $this->input->post('subject_not') ) ); /*$subject_first = $this->input->post('subject_first'); $subject_first[shijian] = array_filter($subject_first[shijian]); $subject_first[fenshu] = array_filter($subject_first[fenshu]); $subject_first[subject_id] = array_filter($subject_first[subject_id]); $subject_first = serialize($subject_first); $subject_two = $this->input->post('subject_two'); $subject_two[shijian] = array_filter($subject_two[shijian]); $subject_two[fenshu] = array_filter($subject_two[fenshu]); $subject_two[subject_id] = array_filter($subject_two[subject_id]); $subject_two = serialize($subject_two); $subject_finish = $this->input->post('subject_finish') ; $subject_finish[rank] = array_filter($subject_finish[rank]); $subject_finish[subject_id] = array_filter($subject_finish[subject_id]); $subject_finish = serialize($subject_finish); $update_xuekao_xuankao = array(); $update_xuekao_xuankao = array( 'is_in_class'=>$is_in_class, 'subject_class'=>$subject_class, 'subject_in'=>$subject_in, 'subject_not'=>$subject_not, 'subject_first'=>$subject_first, 'subject_two'=>$subject_two, 'subject_finish'=>$subject_finish, );*/ if ($uid) { $old_ranking = $old_awards = $old_xuekao_xuankao = array(); $query = $this->db->select('id,grade_id')->get_where('student_ranking', array('uid' => $uid)); foreach ($query->result_array() as $row) { $old_ranking[$row['grade_id']] = $row['id']; } $query = $this->db->select('id')->get_where('student_awards', array('uid' => $uid)); foreach ($query->result_array() as $row) { $old_awards[$row['id']] = $row['id']; } //$old_xuekao_xuankao = $this->db->select('id')->get_where('xuekao_xuankao', array('uid'=>$uid))->row_array(); $db = Fn::db(); $db->beginTransaction(); try { /*if($old_xuekao_xuankao) { $this->db->update('xuekao_xuankao', $update_xuekao_xuankao, array('id'=>$old_xuekao_xuankao['id'])); } else { $update_xuekao_xuankao['uid'] = $uid; $this->db->insert('xuekao_xuankao', $update_xuekao_xuankao); }*/ // 更新成绩排名 foreach ($score_ranking as $grade_id => &$rank) { $rank['uid'] = $uid; if (isset($old_ranking[$grade_id])) { $v = $rank; unset($v['id']); $db->update('rd_student_ranking', $v, "id = " . $old_ranking[$grade_id]); unset($old_ranking[$grade_id]); unset($score_ranking[$grade_id]); } } if ($score_ranking) { foreach ($score_ranking as $v) { $db->insert('rd_student_ranking', $v); } } if ($old_ranking) { $db->delete('rd_student_ranking', 'id IN (' . implode(',', $old_ranking) . ')'); } // 更新获奖情况 $new_awards_list = array(); foreach ($awards_list as $typeid => $type_list) { $new_awards_list = array_merge($new_awards_list, $type_list); } $awards_list = $new_awards_list; foreach ($awards_list as $k => &$awards) { $awards['uid'] = $uid; if ($awards['id'] && isset($old_awards[$awards['id']])) { $v = $awards; unset($v['id']); $db->update('rd_student_awards', $v, 'id = ' . $old_awards[$awards['id']]); unset($old_awards[$awards['id']]); unset($awards_list[$k]); } else { unset($awards['id']); } } if ($awards_list) { foreach ($awards_list as $v) { $db->insert('rd_student_awards', $v); } } if ($old_awards) { $db->delete('rd_student_awards', 'id IN (' . implode(',', $old_awards) . ')'); } if ($volunteer) { $student_wish = array('uid' => $uid, 'music' => '', 'sport' => '', 'painting' => '', 'other' => '', 'wish' => '', 'upmethod' => '', 'volunteer' => $volunteer); } else { $message[] = '第一志愿不能为空'; } $swv = $db->fetchRow("SELECT volunteer FROM rd_student_wish WHERE uid = {$uid}"); if ($swv) { $db->update('rd_student_wish', $student_wish, "uid={$uid}"); } else { $db->insert('rd_student_wish', $student_wish); } $db->commit(); } catch (Exception $e) { $db->rollBack(); message('学生成绩修改失败' . $e->getMessage()); } } else { // 未注册用户,设置session $this->session->set_userdata(array('score_ranks' => $score_ranking, 'awards_list' => $awards_list)); } if ($uid or $this->session->userdata('complete')) { message('学习成绩修改成功', 'student/profile/awards?dl=1', 'success'); } else { redirect('student/profile/basic'); } }