public function buildteam_() { eval(USER); try { // buildteam save $data = safepost('candidates') or throwex(Error('post')); // Check if team can build. $cm = new ContestModel(); $size = $cm->getTeamSize(); $s = countByCond($data, array('statecode' => 1)); if ($s >= $size) { throw new Exception(Error('oversize')); } elseif ($s < $cm->getTeamLower() - 1) { throw new Exception(Error('belowsize')); } // $team_id = DBModel::getTeamByUser(session('userid')); // $model = D('cernet_teammate'); // $model->where(array('team_id'=>$team_id))->delete(); // foreach ($data as $d) { // $_d['team_id'] = $team_id; // $_d['user_id'] = $d['id']; // $_d['statecode'] = $d['statecode']; // $model->add($_d); // } // $_d['team_id'] = $team_id; // $_d['user_id'] = session('userid'); // $_d['statecode'] = 1; // $model->add($_d); // build team // firstly clean useless teammate data $model = D('cernet_teammate'); $model->where(array('team_id' => $_GET['team'], 'statecode' => array('neq', 1)))->delete(); // change team state $model = new AdminModel(); $model->setTeamState($_GET['team'], 4); // state 4: prepare to submit the report. echo "success"; } catch (Exception $e) { echo $e->getMessage(); } }
/** * Rewrite the wrong format excel */ public function rewriteExcel() { require_once "powerdream/Common/PHPExcel.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel2003XML.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel5.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel2007.php"; require_once "powerdream/Common/PHPExcel.php"; // require_once("powerdream/Common/PHPExcel/Writer/Excel2003XML.php"); require_once "powerdream/Common/PHPExcel/Writer/Excel5.php"; require_once "powerdream/Common/PHPExcel/Writer/Excel2007.php"; $excel = new PHPExcel(); $writer = new PHPExcel_Writer_Excel5($excel); $excel->setActiveSheetIndex(0); $objActSheet = $excel->getActiveSheet(); $reader = new PHPExcel_Reader_Excel2007(); # Judge excel type. $filename = str_replace('\\', '/', getcwd()) . $this->filename; if (!$reader->canRead($filename)) { $reader = new PHPExcel_Reader_Excel5(); if (!$reader->canRead($filename)) { $reader = new PHPExcel_Reader_Excel2003XML(); if (!$reader->canRead($filename)) { throwex(Error('import')); } } } #debug(1); $excel = $reader->load($filename); $cursheet = $excel->getSheet(0); $cols = $cursheet->getHighestColumn(); $rows = $cursheet->getHighestRow(); if (strlen($cols) == 2) { $cols = 'Z'; } $count = 1; $map = array('quiz', 'answer', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); # Traverse the excel table and insert them into DB for ($currow = 2; $currow <= $rows; $currow++) { # Traverse the columns for each row for ($curcol = 'A'; $curcol <= $cols; $curcol++) { $now = $curcol . $currow; $value = $cursheet->getCell($now)->getValue(); if ($value == null || $value == '') { break; } if ($value instanceof PHPExcel_RichText) { //富文本转换字符串 $value = $value->__toString(); } $objActSheet->setCellValue($now, $value); } } $writer->save("Downloads/excel/rewrite.xls"); }
/** * get Problems * @return array */ function readExcel() { require_once "powerdream/Common/PHPExcel.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel2003XML.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel5.php"; require_once "powerdream/Common/PHPExcel/Reader/Excel2007.php"; $excel = new PHPExcel(); $reader = new PHPExcel_Reader_Excel2007(); # Judge excel type. if (!$reader->canRead($filename)) { $reader = new PHPExcel_Reader_Excel5(); if (!$reader->canRead($filename)) { $reader = new PHPExcel_Reader_Excel2003XML(); if (!$reader->canRead($filename)) { throwex($Error['import']); } } } $excel = $reader->load($filename); $cursheet = $excel->getSheet(0); $cols = $cursheet->getHighestColumn(); $rows = $cursheet->getHighestRow(); #var_dump($cols); #var_dump($rows); #var_dump($cursheet); if (strlen($cols) == 2) { $cols = 'Z'; } $stdlist = array(); $map = array("sid", "sname", "gender", "grade", "major", "class", "email", "mobile", "short", "domitory"); for ($currow = 2; $currow <= $rows; $currow++) { $m = 1; $student = array(); $i = 0; for ($curcol = 'A'; $curcol <= $cols; $curcol++) { $now = $curcol . $currow; $value = $cursheet->getCell($now)->getValue(); $student[$map[$i]] = $value; $i++; } $student["password"] = encrypt($student["sid"]); $student["time"] = date("Y-m-d H:i:s"); array_push($stdlist, $student); } return $stdlist; }
public function teacher() { eval(ADMIN); if (!isset($_GET['show'])) { throwex(Error("get")); } else { $userId = $_GET['show']; } $list = DBModel::getByFields('cernet_teacher', array('id' => $userId)); $this->assign('list', $list[0]); eval(NDSP); }