Esempio n. 1
0
 public function __construct($year)
 {
     if (!isset($year)) {
         $year = ContestModel::getCurrentYear();
     }
     $this->year = $year;
     $cond['id'] = $year;
     if (!DBModel::existUser('cernet_contest', $cond)) {
         DBModel::insertDB('cernet_contest', $cond);
     }
 }
Esempio n. 2
0
 /**
  * store the men and the teams in the table--second_award
  * @author panda
  */
 public function storeAward()
 {
     $year = ContestModel::getCurrentYear();
     $tables = ['cernet_user', 'cernet_team', 'cernet_teacher'];
     $model = new DBModel();
     for ($i = 0; $i < 3; $i++) {
         $users = $model->getAward($tables[$i]);
         foreach ($users as $user) {
             $data = array('user_type' => $i, 'user_id' => $user['id'], 'award' => $user['prize'], 'contest_id' => $year);
             $model->insertDB('second_award', $data);
         }
     }
 }
Esempio n. 3
0
 public function award()
 {
     $cond['contest_id'] = (int) ContestModel::getCurrentYear();
     $awards = DBModel::getByFields('second_award', $cond);
     $tables = ['second_user', 'second_team', 'second_teacher'];
     foreach ($awards as $k => $v) {
         $awards[$k]['uname'] = getNameById($tables[$v['user_type']], $v['user_id']);
         $awards[$k]['contest'] = $v['contest_id'];
         $awards[$k]['award'] = $v['award'];
     }
     $this->assign("award", $awards);
     $this->assign("type", $tables);
     $this->assign("less", "about" . ".less");
     eval(NDSP);
 }
Esempio n. 4
0
 public function buildteam_save_()
 {
     eval(USER);
     try {
         // dump($_POST);
         $data = safepost('candidates');
         $contest = new ContestModel();
         $size = $contest->getTeamSize();
         if (countByCond($data, array('statecode' => 1)) > $size) {
             throw new Exception(Error('oversize'));
         }
         $team_id = DBModel::getTeamByUser(session('userid'));
         $model = D('cernet_teammate');
         $model->where(array('team_id' => $team_id))->delete();
         foreach ($data as $d) {
             // dump($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);
         // $this->goback();
         echo "success";
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 5
0
<?php

session_start();
include_once '../includes/connection.php';
include_once '../includes/Contest.php';
include_once '../includes/tipoRespuesta.php';
include_once '../PDO/ContestModel.php';
include_once '../includes/Answer.php';
include_once '../PDO/AnswerModel.php';
$tipo = new TipoRespuesta();
if (isset($_SESSION['name']) and $_SESSION['id'] == '10207674962976867') {
    $id_event = $_GET['id_event'];
    $id_type = $_GET['id_type'];
    $contest = new Contest();
    $contestModel = new ContestModel();
    $answer = new Answer();
    $answerModel = new AnswerModel();
    $tipos = $tipo->fetch_all();
    if (isset($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'update':
                $contest->__SET('id_event', $_REQUEST['id_event']);
                $contest->__SET('name', $_REQUEST['name']);
                $contest->__SET('question', $_REQUEST['question']);
                $contest->__SET('id_type', $_REQUEST['tiposelect']);
                $contest->__SET('initial_date', $_REQUEST['initial_date']);
                $contest->__SET('final_date', $_REQUEST['final_date']);
                $contest->__SET('winner', $_REQUEST['winner']);
                $contest->__SET('active', 1);
                $contestModel->Update($contest);
                //echo '<script language="javascript">alert("¡El registro se ha actualizado exitosamente!");</script>';
Esempio n. 6
0
/**
 * Use PHPExcel to export Excel of a team.
 */
function writeTeamExcel($info, $title, $content)
{
    function excelchr($index)
    {
        if ($index <= 90) {
            return chr($index);
        }
        $k = ($index - 65) / 26;
        $k2 = ($index - 65) % 26;
        if ($k2 == 0) {
            $k2 = 1;
        } else {
            $k2++;
        }
        return chr($k + 64) . chr($k2 + 64);
    }
    function getName_($key, $val)
    {
        switch ($key) {
            case 'university':
                return getNameById('cernet_university', $val);
            case 'teacher':
                return getNameById('cernet_teacher', $val);
            case 'city':
                return getNameById('cernet_city', $val);
            case 'degree':
                return getNameById('cernet_degree', $val);
            case 'major':
                return getNameById('cernet_major', $val);
            case 'tutor_id':
                return getNameById('cernet_tutor', $val);
            case 'report_id':
                return getNameById('cernet_report', $val);
            case 'leader':
                return getNameById('cernet_user', $val);
            default:
                return $val;
        }
    }
    function strip($team)
    {
        $key = 'teacher';
        $res[$key] = array();
        $fn = array('id', 'name', 'organization', 'job', 'email', 'phone');
        foreach ($team[$key] as $k => $t) {
            if (in_array($k, $fn)) {
                $res[$key][$k] = $t;
            }
        }
        $key = 'tutor';
        $res[$key] = array();
        $fn = array('id', 'name', 'email', 'mobile');
        foreach ($team[$key] as $k => $t) {
            if (in_array($k, $fn)) {
                $res[$key][$k] = $t;
            }
        }
        $key = 'team';
        $res[$key] = array();
        $fn = array('id', 'name', 'leader', 'university', 'report_id', 'prize');
        foreach ($team[$key] as $k => $t) {
            if (in_array($k, $fn)) {
                $res[$key][$k] = $t;
            }
        }
        $key = 'teammate';
        $res[$key] = array();
        $fn = array('id', 'name', 'gender', 'major', 'college', 'university', 'city', 'mobile', 'email', 'degree', 'address', 'zipcode');
        foreach ($team[$key] as $kk => $tk) {
            foreach ($tk as $k => $t) {
                if (in_array($k, $fn)) {
                    $res[$key][$kk][$k] = $t;
                }
            }
        }
        return $res;
    }
    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);
    # Basic info
    $config = C('ADMIN');
    $props = $excel->getProperties();
    $props->setCreator($config['NAME']);
    $props->setLastModifiedBy($config['NAME']);
    $props->setTitle($info['title']);
    $excel->setActiveSheetIndex(0);
    $objActSheet = $excel->getActiveSheet();
    $objActSheet->setTitle($info["title"]);
    # Build Title row
    // $title = array('队伍ID', '队伍名字', '队长', '队伍高校', '选题报告', '所获奖项', '指导老师ID', '指导老师', '教师工作单位', '教师职位', '教师邮箱', '教室电话', '企业导师ID', '企业导师', '企业导师邮箱', '企业导师电话', '队员1ID', '队员1名字', '队员1性别', '队员1城市', '队员1学校', '队员1学院', '队员1专业', '队员1邮箱', '队员1手机', '队员1学历', '队员1地址', '队员1邮编', '队员2ID', '队员2名字', '队员2性别', '队员2城市', '队员2学校', '队员2学院', '队员2专业', '队员2邮箱', '队员2手机', '队员2学历', '队员2地址', '队员2邮编', '队员3ID', '队员3名字', '队员3性别', '队员3城市', '队员3学校', '队员3学院', '队员3专业', '队员3邮箱', '队员3手机', '队员3学历', '队员3地址', '队员3邮编', '队员4ID', '队员4名字', '队员4性别', '队员4城市', '队员4学校', '队员4学院', '队员4专业', '队员4邮箱', '队员4手机', '队员4学历', '队员4地址', '队员4邮编');
    $title = array('队伍ID', '队伍名字', '队长', '队伍高校', '选题报告', '所获奖项', '指导老师ID', '指导老师', '教师工作单位', '教师职位', '教师邮箱', '教室电话', '企业导师ID', '企业导师', '企业导师邮箱', '企业导师电话');
    $cm = new ContestModel();
    for ($i = 1; $i <= $cm->getTeamSize(); $i++) {
        $arr_ = array("队员{$i} ID", "队员{$i} 名字", "队员{$i} 性别", "队员{$i} 城市", "队员{$i} 学校", "队员{$i} 学院", "队员{$i} 专业", "队员{$i} 邮箱", "队员{$i} 手机", "队员{$i} 学历", "队员{$i} 地址", "队员{$i} 邮编");
        $title = array_merge($title, $arr_);
    }
    $len = count($title);
    for ($i = 0; $i < $len; $i++) {
        if ($title[$i] != null) {
            $objActSheet->setCellValue(excelchr($i + 65) . '1', $title[$i]);
            # Fill in the contents
            $objActSheet->getStyle(excelchr($i + 65) . '1')->getFont()->setBold(true);
            # Set title bold font
            #$objActSheet->getColumnDimension(chr($i+65))->setWidth(12);		# Set column width
            #$objActSheet->getColumnDimension(chr($i+65))->setAutoSize(true);
        }
    }
    # Fill in the contents rows
    $iterkey = array('team', 'teacher', 'tutor');
    for ($j = 2; $j < 2 + count($content); $j++) {
        $i = 0;
        $content[$j - 2] = strip($content[$j - 2]);
        foreach ($iterkey as $key0) {
            foreach ($content[$j - 2][$key0] as $k => $v) {
                $v = getName_($k, $v);
                $objActSheet->setCellValue(excelchr($i + 65) . $j, $v);
                $objActSheet->getStyle(excelchr($i + 65) . $j)->getAlignment()->setWrapText(true);
                $objActSheet->getColumnDimension(excelchr($i + 65))->setWidth(15);
                $i++;
            }
        }
        // write teammates
        foreach ($content[$j - 2]['teammate'] as $teammates) {
            foreach ($teammates as $k => $v) {
                $v = getName_($k, $v);
                $objActSheet->setCellValue(excelchr($i + 65) . $j, $v);
                $objActSheet->getStyle(excelchr($i + 65) . $j)->getAlignment()->setWrapText(true);
                $objActSheet->getColumnDimension(excelchr($i + 65))->setWidth(15);
                $i++;
            }
        }
    }
    // dump($objActSheet);
    # Use id & time to generate a unique filename
    $time = time();
    $id = $info["id"];
    $writer->save("Downloads/excel/export_{$id_}{$time}.xls");
    // debug();
    return "Downloads/excel/export_{$id_}{$time}.xls";
}
Esempio n. 7
0
 /**
  * Admin can manage all the notices here.
  */
 public function manage_notice()
 {
     eval(ADMIN);
     // show the list of a year
     $year = $_GET["year"];
     if (!isset($_GET["year"])) {
         $year = ContestModel::getCurrentYear();
     }
     $cond["time"] = array("like", "{$year}%");
     $noticelist = DBModel::getByFields("cernet_notice", $cond, true, 'time DESC');
     $this->assign("noticelist", $noticelist);
     // show the year list
     $yearlist = DBModel::sqlquery("cernet_notice", "SELECT LEFT(time, 4) FROM `cernet_notice` GROUP BY LEFT(time, 4)");
     $this->assign("yearlist", $yearlist);
     // dump($yearlist);
     $this->assign("less", __FUNCTION__ . ".less");
     eval(NDSP);
 }