public function __construct() { parent::__construct('adm_smen_tadd'); $id_categ_select = null; $this->data['proc_value'] = 50; $error = null; $this->data['select'][] = 0; if (isset($_POST['submit'])) { if (empty($_POST['name'])) { $error[] = 'testname'; } if (empty($_POST['proc']) || !($_POST['proc'] >= 0 && $_POST['proc'] <= 100)) { $error[] = 'proc'; } if (empty($_POST['categ'])) { $error[] = 'categ'; } if (isset($error)) { if (!empty($_POST['proc'])) { $this->data['proc_value'] = $_POST['proc']; } if (!empty($_POST['name'])) { $this->data['select']['testname'] = $_POST['name']; } if (!empty($_POST['alguest'])) { $this->data['select']['alguest'] = 'checked'; } if (!empty($_POST['categ'])) { $id_categ_select = (int) $_POST['categ']; } $this->data['alert'] = array('type' => 'warning', 'mess' => $error); } else { if (empty($_POST['alguest'])) { $_POST['alguest'] = 0; } $this->mysql = db::getInstance(); $this->mysql->executeQuery("INSERT INTO `test` (`t_test_name`, `id_category`, `t_allow_guest`, `t_min_true`) VALUES (:name, :idcat, :algst, :mintrue)", array(array(':name', $_POST['name'], 'string'), array(':idcat', (int) $_POST['categ'], 'integer'), array(':algst', (int) $_POST['alguest'], 'integer'), array(':mintrue', $_POST['proc'], 'string'))); $this->data['alert'] = array('type' => 'success', 'mess' => array('add_testg')); } } $k = new m_part_categ(); $v = new v_part_categ($k->getData(), $id_categ_select); $this->data['category'] = $v->cont; }
public function __construct() { parent::__construct('adm_ques_add'); $this->data['quest'] = ''; $id_categ_select = null; $error = array(); if (isset($_POST['submit'])) { if (empty($_POST['type'])) { $error[] = 'type'; } if (empty($_POST['quest'])) { $error[] = 'quest'; } if (empty($_POST['categ'])) { $error[] = 'categ'; } if ($_POST['type'] == 'type_1') { $type = 1; if (empty($_POST['ans1'][1]) || empty($_POST['ans1'][2])) { $error[] = 'ans'; } if (!(isset($_POST['true1']) && !empty($_POST['true1']) && count($_POST['true1']) === 1)) { $error[] = 'ans1'; } } if ($_POST['type'] == 'type_2') { $type = 2; if (empty($_POST['ans2'][1]) || empty($_POST['ans2'][2])) { $error[] = 'ans'; } if (!(isset($_POST['true2']) && !empty($_POST['true2']) && count($_POST['true2']) > 1)) { $error[] = 'ans2'; } } if (!empty($_FILES['file'])) { foreach ($_FILES["file"]["error"] as $key => $error_file) { if (!empty($_FILES["file"]["name"][$key])) { if ($error_file == UPLOAD_ERR_OK) { $name = $_FILES["file"]["name"][$key]; $file_size = $_FILES["file"]["size"][$key]; $ext = pathinfo($name, PATHINFO_EXTENSION); if (!($ext == 'jpg' || $ext == 'jpeg' || $ext == 'bmp' || $ext == 'png' || $ext == 'gif')) { $error[] = 'file_ext'; } if ($file_size > MAXFILEUPLOADSIZE) { //MAX 100M $error[] = 'file_error'; } } else { $error[] = 'file_error'; } } } } // Если есть ошибки if (!empty($error)) { $this->data['quest'] = $_POST['quest']; if (!empty($_POST['categ'])) { $id_categ_select = (int) $_POST['categ']; } if ($type == 1) { $this->data['select']['type1'] = 'selected'; if (!empty($_POST['true1'][0])) { $this->data['select']['true1' . (int) $_POST['true1'][0]] = 'checked'; } foreach ($_POST['ans1'] as $k => $an) { $this->data['select']['ans1' . $k] = $an; } } if ($type == 2) { $this->data['select']['type2'] = 'selected'; if (!empty($_POST['true2'])) { foreach ($_POST['true2'] as $tru) { $this->data['select']['true2' . (int) $tru] = 'checked'; } } foreach ($_POST['ans2'] as $k => $an) { $this->data['select']['ans2' . $k] = $an; } } $this->data['alert'] = array('type' => 'warning', 'mess' => $error); } else { $this->mysql = db::getInstance(); $this->mysql->executeQuery("INSERT INTO `question` (`id_question_type`, `id_category`, `q_text`) VALUES (:type, :category, :text)", array(array(':type', $type, 'integer'), array(':category', (int) $_POST['categ'], 'integer'), array(':text', $_POST['quest'], 'string'))); $l_id = (int) $this->mysql->lastInsertId(); if ($type === 1) { foreach ($_POST['ans1'] as $k => $v) { $v = $v; if (!empty($v)) { if ($k == (int) $_POST['true1'][0]) { $tr = array(':tr', 1, 'integer'); } else { $tr = array(':tr', null, 'null'); } $this->mysql->executeQuery("INSERT INTO `answer` (`id_question`, `a_text`, `a_is_true`) VALUES (:id, :text, :tr)", array(array(':id', $l_id, 'integer'), array(':text', $v, 'string'), $tr)); } } } if ($type === 2) { foreach ($_POST['ans2'] as $k => $v) { $v = $v; if (!empty($v)) { $tr = array(':tr', null, 'null'); foreach ($_POST['true2'] as $tru) { if ((int) $tru === $k) { $tr = array(':tr', 1, 'integer'); break; } } $this->mysql->executeQuery("INSERT INTO `answer` (`id_question`, `a_text`, `a_is_true`) VALUES (:id, :text, :tr)", array(array(':id', $l_id, 'integer'), array(':text', $v, 'string'), $tr)); } } } if (!empty($_FILES['file'])) { $root_folder = UPLOADPATH; $img_num = 0; foreach ($_FILES["file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $img_num++; $tmp_name = $_FILES["file"]["tmp_name"][$key]; $name = $_FILES["file"]["name"][$key]; $ext = pathinfo($name, PATHINFO_EXTENSION); $last_file_id = (int) $this->putFile($name, $ext, $tmp_name, $root_folder); $this->mysql->executeQuery("INSERT INTO `question_option` (`id_question`, `qo_text`, `id_file`) VALUES (:id, :text, :id_file)", array(array(':id', $l_id, 'integer'), array(':text', 'Изображение-' . $img_num, 'string'), array(':id_file', $last_file_id, 'integer'))); } } } $this->data['alert'] = array('type' => 'success', 'mess' => array('add_quest')); } } $k = new m_part_categ(); $v = new v_part_categ($k->getData(), $id_categ_select); $this->data['category'] = $v->cont; }