diff --git a/application/config/database.php b/application/config/database.php index a4e436c..fb43f8d 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -50,7 +50,7 @@ $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; -$db['default']['password'] = ''; +$db['default']['password'] = '666999'; $db['default']['database'] = 'deti'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; diff --git a/application/controllers/question.php b/application/controllers/question.php index 70b8c8f..78cf161 100755 --- a/application/controllers/question.php +++ b/application/controllers/question.php @@ -32,13 +32,20 @@ public function index(){ } public function show($question_id=0){ - $q_data['question'] = $this->Question_model->get_question($question_id); - $a_data['answers'] = $this->Answer_model->get_answers($question_id); - $this->load->view('questionView', $q_data, $a_data); + $this->load->model('Answer_model'); + $data['question'] = $this->Question_model->get_question($question_id); + $data['answers'] =$this->Answer_model->get_answers($question_id); + $this->load->view('questionView', $data); } public function setQuestion(){ } + + public function deleteQuestion($question_id, $type){ + + $this->Question_model->delete_question($question_id); + redirect('/admin/questions/'.$type); + } } ?> diff --git a/application/models/answer_model.php b/application/models/answer_model.php old mode 100644 new mode 100755 index 4e98dc6..5894f41 --- a/application/models/answer_model.php +++ b/application/models/answer_model.php @@ -23,9 +23,9 @@ function add_answer($text) return $this->db->insert_id(); } - function get_answers($type = 'all') + function get_answers($question_id) { - $this->db->select('questions.*, users.*')->from('questions')->join('users', 'users.user_id = questions.user_id', 'left'); + $this->db->select('answers.*, users.*')->from('answers')->join('users', 'users.user_id = answers.user_id', 'left')->where('question_id',$question_id); $query = $this->db->get(); return $query->result(); } diff --git a/application/models/question_model.php b/application/models/question_model.php index 14a3b31..2405948 100755 --- a/application/models/question_model.php +++ b/application/models/question_model.php @@ -22,12 +22,63 @@ function add_question($text) // send_sms('+380937444376', 'Q: ' . mb_substr($text, 0, 67)); return $this->db->insert_id(); } + /*public function get_questions($type = 'all'){ + return $type; + }*/ function get_questions($type = 'all') - { - $this->db->select('questions.*, users.*')->from('questions')->join('users', 'users.user_id = questions.user_id', 'left'); - $query = $this->db->get(); - return $query->result(); + { //$type=$this->get_questions(); + switch($type){ + case "all": + $this->db->select('questions.*, users.*')->from('questions')->join('users', 'users.user_id = questions.user_id', 'left'); + $query = $this->db->get(); + return $query->result(); + break; + case "no_answer": + $sql = "SELECT questions.*, users.*, COUNT(`answers`.`answer_id`) AS `answers_count` FROM `questions` +LEFT JOIN `answers` ON `answers`.`question_id` = `questions`.question_id +LEFT JOIN `users` ON `users`.`user_id` = `questions`.user_id +GROUP BY `questions`.`question_id`"; + $arr = $this->db->query($sql)->result(); + if (is_array($arr) && count($arr)) { + foreach ($arr as $key => $record) { + if ($arr[$key]->answers_count == 0) { + unset($arr[$key]); + //да, ми знаэмо що це лайно. проблема вирішена в файлі Question_site_model.php + } + } + } + return $arr; + + break; + case "answered": + $sql = "SELECT questions.*, users.*, COUNT(`answers`.`answer_id`) AS `answers_count` FROM `questions` +LEFT JOIN `answers` ON `answers`.`question_id` = `questions`.question_id +LEFT JOIN `users` ON `users`.`user_id` = `questions`.user_id +GROUP BY `questions`.`question_id`"; + $arr = $this->db->query($sql)->result(); + if (is_array($arr) && count($arr)) { + foreach ($arr as $key => $record) { + if ($arr[$key]->answers_count > 0) { + unset($arr[$key]); + //да, ми знаэмо що це лайно. проблема вирішена в файлі Question_site_model.php + } + } + } + return $arr; + + break; + case "psych": + $this->db->select('questions.*, users.*')->from('questions')->join('users', 'users.user_id = questions.user_id', 'left')->where('psych','1'); + $query = $this->db->get(); + + return $query->result(); + break; + + } + + + } @@ -58,13 +109,13 @@ function get_user_questions_nu($user_id = '0', $start_id = 0) return $this->db->query($sql)->result(); } - function unanswered_count() + /*function unanswered_count() { $this->db->select('COUNT(*) as `count`')->from('questions')->where('(`questions`.`answer` IS NULL) OR (`questions`.`answer` = \'\')'); $query = $this->db->get(); $return = $query->result(); return $return[0]->count; - } + }*/ function delete_question($question_id) { @@ -91,4 +142,6 @@ function delete_answered_questions_today_yesterday() $sql = "DELETE FROM `questions` WHERE `answer` IS NOT NULL AND `answer` != '' AND (DATE(`answer_datetime`) = DATE('" . date('Y-m-d', strtotime('-1 day')) . "') OR DATE(`answer_datetime`) = DATE('" . date('Y-m-d', strtotime('-2 day')) . "'))"; return $this->db->query($sql); } + + } \ No newline at end of file diff --git a/application/views/admin/questions.php b/application/views/admin/questions.php index 783bdad..c7e3ec8 100755 --- a/application/views/admin/questions.php +++ b/application/views/admin/questions.php @@ -1,11 +1,14 @@
+ Все Без ответов С ответами + Помощь психолога
@@ -20,10 +23,12 @@
-
+
+question_id;?> +
- text; ?> + text;?>
diff --git a/application/views/admin/template.php b/application/views/admin/template.php index 1e5c627..e8d446b 100755 --- a/application/views/admin/template.php +++ b/application/views/admin/template.php @@ -14,9 +14,9 @@
diff --git a/application/views/questionView.php b/application/views/questionView.php index b9049e3..20d529d 100755 --- a/application/views/questionView.php +++ b/application/views/questionView.php @@ -1,8 +1,11 @@
- -

text; ?>

+

text; ?>

date));?>
text;?>
+
+
+
+

\ No newline at end of file diff --git a/js/admin.js b/js/admin.js old mode 100644 new mode 100755 index 1d10bb4..8856b46 --- a/js/admin.js +++ b/js/admin.js @@ -367,10 +367,7 @@ var this_ = this; //if (confirm('Действительно хотите удалить вопрос?')) { jQuery.post('/admin/question', {'action': 'delete', 'question_id': jQuery(this).parent().parent().parent().attr('question_id')}, function(data) { - jQuery('.unanswered_count').html(data); - jQuery(this_).parent().parent().parent().hide(500, function() { - jQuery(this).remove(); - }); + document.location.reload(); }); //} }); diff --git a/sxd/backup/deti_2014-12-13_22-53-37.sql.gz b/sxd/backup/deti_2014-12-13_22-53-37.sql.gz old mode 100644 new mode 100755 diff --git a/sxd/backup/deti_2014-12-13_22-53-54.sql.gz b/sxd/backup/deti_2014-12-13_22-53-54.sql.gz old mode 100644 new mode 100755