public function action_index() { $email = Security::xss_clean(Arr::get($this->post, 'email', '')); $user = ORM::factory('User')->where('email', '=', $email)->find(); if ($user->loaded() && $user->network_reg == 0 && empty($user->link_activate)) { $date = date("Y-m-d H:i:s"); $code = md5($date . $user->password); Email::connect(); Email::View('reminderapi'); Email::set(array('username' => $user->username, 'id' => $code, 'url' => URL::media($this->language . '/auth/recovery/', true))); Email::send($user->email, array('*****@*****.**', 'e-history.kz'), "E-history.kz, ссылка для смены пароля.", '', true); $save_code = ORM::factory('User', $user->id); $save_code->link_recovery = $code; $save_code->save(); $this->data = true; } else { $this->data['error'] = 'Email is not registered'; } $this->response->body(json_encode($this->data)); }
public function action_agree() { $id = (int) $this->request->param('id', 0); if (!Auth::instance()->logged_in()) { Message::success(i18n::get('You can not participate in this debate')); $this->redirect('debate', 301); } $debate = ORM::factory('Debate', $id); $nowdate = date('Y-m-d H:i:s'); $date = date('Y-m-d H:i:s', strtotime("+36 hours", strtotime($debate->date))); if ($debate->opponent_email == Auth::instance()->get_user()->email and $debate->is_closed == 0 and $debate->is_public == 0 or $date < $nowdate) { $date = date('Y-m-d H:i:s'); $debate->start_time = $date; $debate->end_time = date('Y-m-d H:i:s', strtotime("+" . $debate->lifetime . " hours", strtotime($date))); $debate->opponent_id = Auth::instance()->get_user()->id; $debate->is_public = 1; $debate->replier_id = $debate->author_id; $debate->save(); $user_id = Auth::instance()->get_user()->id; $user = ORM::factory('User', $debate->author_id); $email = $user->profile->email; $opponent = $user->username; $user = ORM::factory('User', $user_id); $author = $user->username; $debate_link = Url::site("debate/view/" . $debate->id, true); Message::success(i18n::get('You have agreed to participate in the debates. Notification to this effect was sent to your opponent')); Email::connect(); Email::View('debate_agree'); Email::set(array('opponent' => $opponent, 'author' => $author, 'link' => 'e-history.kz', 'theme' => "<a href='" . $debate_link . "'>'" . $debate->title . "'</a>")); Email::send($email, array('*****@*****.**', 'e-history.kz'), __("Ваш оппонент согласился участвовать в дебатах на портале :link", array(':link' => 'History.kz')), '', true); $this->redirect('debate/view/' . $id, 301); } else { if ($date < $nowdate) { Message::success(i18n::get('Expired 36 hours during which you could agree to take part in the debate')); } else { Message::success(i18n::get('You can not give consent to participate in this debate')); } $this->redirect('debate', 301); } }
public function action_materials() { if (!Auth::instance()->logged_in()) { $this->redirect('/', 301); } $user_id = $this->user->id; $materials = ORM::factory('Material')->where('user_id', '=', $user_id); $paginate = Paginate::factory($materials)->paginate(NULL, NULL, 3)->render(); $materials = $materials->find_all(); $this->set('materials', $materials); $this->set('paginate', $paginate); $uploader = View::factory('storage/materials')->set('user_id', $user_id)->render(); $this->set('uploader', $uploader); if ($this->request->method() == Request::POST) { $journal = (int) Arr::get($_POST, 'material_type', 0); if ($journal !== 1) { $journal = 0; } try { $material = ORM::factory('Material'); $material->theme = substr(Arr::get($_POST, 'theme', ''), 0, 250); $material->message = substr(Arr::get($_POST, 'message', ''), 0, 500); $material->user_id = $user_id; $material->date = date('Y-m-d H:i:s'); $material->lang_notice = strtolower(Kohana_I18n::lang()); if ($journal) { $material->is_journal = 1; $material->is_moderator = 0; } $material->save(); $files = Arr::get($_POST, 'files', ''); if ($files) { foreach ($files as $key => $file) { if ($key > 7) { break; } if ($file) { $storage = ORM::factory('Storage', (int) $file); try { $upload = ORM::factory('Material_File'); $upload->user_id = $user_id; $upload->material_id = $material->id; $upload->date = date('Y-m-d H:i:s'); $upload->storage_id = (int) $file; $upload->filesize = filesize($storage->file_path); $upload->save(); } catch (ORM_Validation_Exception $e) { } } } } Message::success(i18n::get('The material sent to the moderator. Thank you!')); $user = ORM::factory('User', $user_id); $user_email = $user->email; Email::connect(); Email::View('review_now_' . i18N::lang()); Email::set(array('message' => I18n::get('Оставленный вами материал находится на рассмотрении редакционной коллегии портала'))); Email::send($user_email, array('*****@*****.**', 'e-history.kz'), I18n::get('Рассмотрение материала на портале "История Казахстана" e-history.kz'), '', true); if ($journal != 1) { $material_type = 'Интересные материалы'; $url = URL::media('/manage/materials', TRUE); } else { $material_type = 'Журнал e-history'; $url = URL::media('/manage/materials/ehistory', TRUE); } $user_profile = ORM::factory('User_Profile', $user_id); if ($user_profile->first_name != '') { $user_name = $user_profile->first_name . ' ' . $user_profile->last_name; } else { $user_name = $user->username; } $email = '*****@*****.**'; Email::connect(); Email::View('new_material'); Email::set(array('url' => $url, 'material_type' => $material_type, 'username' => $user_name)); Email::send($email, array('*****@*****.**', 'e-history.kz'), "Новый материал на e-history.kz", '', true); $this->redirect('profile/materials', 301); } catch (ORM_Validation_Exception $e) { $errors = $e->errors($e->alias()); $files = Arr::get($_POST, 'files', ''); $this->set('errors', $errors)->set('material', $_POST)->set('files', $files); } } $this->add_cumb('User profile', 'profile'); $this->add_cumb('Downloaded Content', '/'); }
protected function _execute(array $params) { $report_list = array(); $start = microtime(true); //получаем список юзеров имеющих подписки $user_list = ORM::factory('Subscription')->group_by('user_id')->find_all(); foreach ($user_list as $oneuser) { set_time_limit(30); $user_id = $oneuser->user_id; $lang = ORM::factory('Subscription_Setting')->where('user_id', '=', $user_id)->find()->lang; $lang_arr = array('ru', 'en', 'kz', 'RU', 'EN', 'KZ'); if (!in_array($lang, $lang_arr)) { $lang = 'ru'; } $period = ORM::factory('Subscription_Setting')->where('user_id', '=', $user_id)->find()->period; $user = ORM::factory('User', $user_id); $user_profile = ORM::factory('User_Profile', $user_id); $update_time = false; $period_arr = array('1', '2', '3'); if (!in_array($period, $period_arr)) { $update_time = true; } if ($period == '1') { $update_time = true; } if ($period == '2') { if (date('N') == 1) { $update_time = true; } } if ($period == '3') { if (date('j') == 1) { $update_time = true; } } //Как обращаться к пользователю if ($user_profile->first_name != '') { $user_name = $user_profile->first_name . ' ' . $user_profile->last_name; } else { $user_name = $user->username; } //На какое мыло слать $user_email = $user->email; //выставляем язык для рассылки I18n::lang($lang); //получаем список подписок текущего пользователя $sub_list = ORM::factory('Subscription')->where('user_id', '=', $user_id)->find_all(); $links = array(); //ищем самую старую дату из всех подписок $lastdate = '3000-01-01 00:00:00'; foreach ($sub_list as $sub) { if ($lastdate > $sub->date) { $lastdate = $sub->date; } } //если пришло время обновляться if ($update_time == true) { //перебираем список подписок текущего юзера foreach ($sub_list as $sub) { //Получаем запись из Pages, на которую подписан юзер $page = ORM::factory('Page', $sub->category_id); //Смотрим ключ записи, если ключ пустой то ищем имя ключа родителя $key = $page->key; if ($page->key == '' and $page->lvl == '3') { $page_lvl = ORM::factory('Page', $page->parent_id)->as_array(null, 'key'); $key = $page_lvl['key']; } //перебираем все варианты ключей //История казахстана и подразделы if ($key == 'history') { set_time_limit(30); if ($page->lvl == 2) { $allsubhistory = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all()->as_array(null, 'id'); $allsubhistory = ORM::factory('Page')->where('parent_id', 'in', $allsubhistory)->find_all()->as_array(null, 'id'); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { if (count(Subtool::findincontents($inlog, $allsubhistory)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } if ($page->lvl == 3) { $allsubhistory = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all()->as_array(null, 'id'); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { if (count(Subtool::findincontents($inlog, $allsubhistory)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } } //Первый президент и подразделы if ($key == 'president') { set_time_limit(30); if ($page->lvl == 3) { if ($page->key == '') { $find_child = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all()->as_array(null, 'id'); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($find_child) > 0) { if (count($inlog) > 0) { if (count(Subtool::findincontents($inlog, $find_child)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } else { if (count($inlog) > 0) { $find_child[] = $sub->category_id; if (count(Subtool::findincontents($inlog, $find_child)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } } } if ($page->lvl == 2) { $president = false; $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all(); foreach ($find_child_lvl3 as $child_lvl3) { if ($president == false) { if ($child_lvl3->key == '') { $find_child = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all()->as_array(null, 'id'); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($find_child) > 0) { if (count($inlog) > 0) { if (count(Subtool::findincontents($inlog, $find_child)) > 0) { $president = true; } } } else { if (count($inlog) > 0) { $find_child[] = $sub->category_id; if (count(Subtool::findincontents($inlog, $find_child)) > 0) { $president = true; } } } } $e = explode('_', $page->key); if ($e[0] == 'books' and isset($e[2])) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); $cats[] = $e[2]; if (count($inlog) > 0) { if (count(Subtool::findinbooks($inlog, $cats)) > 0) { $president = true; } } } } } if ($president == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } //Экспертный взгляд и подразделы if ($key == 'expert' and $page->key == 'expert' and $page->lvl == 3) { set_time_limit(30); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Expert_Opinion'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'expert' and $page->key == '' and $page->lvl == 3) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $sub->category_id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } if ($key == 'expert' and $page->lvl == 2) { set_time_limit(30); $expert = false; $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all(); foreach ($find_child_lvl3 as $child_lvl3) { if ($expert == false) { if ($child_lvl3->key == 'expert') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Expert_Opinion'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $expert = true; } } if ($child_lvl3->key == '') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $child_lvl3->id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $expert = true; } } } } } if ($expert == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //Электронный архив и подразделы if ($key == 'archive' and $page->lvl == 3) { set_time_limit(30); $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all(); if (count($find_child_lvl3) > 0) { $archive_lvl3 = false; foreach ($find_child_lvl3 as $child_lvl3) { if ($archive_lvl3 == false) { $allsub = array(); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $child_lvl3->id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $archive_lvl3 = true; } } } } if ($archive_lvl3 == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $sub->category_id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } } if ($key == 'archive' and $page->lvl == 2) { $find_all_child = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all(); $archive_lvl3 = false; foreach ($find_all_child as $finded_child) { if ($archive_lvl3 == false) { set_time_limit(30); $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $finded_child->id)->find_all(); $archive_lvl3 = false; if (count($find_child_lvl3) > 0) { foreach ($find_child_lvl3 as $child_lvl3) { $allsub = array(); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $child_lvl3->id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $archive_lvl3 = true; } } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsub[] = $finded_child->id; if (count(Subtool::findincontents($inlog, $allsub)) > 0) { $archive_lvl3 = true; } } } } } if ($archive_lvl3 == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //Персоналии if ($key == 'biography' and $page->lvl == 3) { $all_biography_lvl4 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); foreach ($all_biography_lvl4 as $biography_lvl4) { set_time_limit(30); $newbiography = false; $e = explode('_', $biography_lvl4->key); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Biography'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $biography = ORM::factory('Biography')->where('id', 'in', $inlog)->and_where('category_id', '=', $e[1])->find_all()->as_array(null, 'id'); if (count($biography) > 0) { $newbiography = true; } } } if ($newbiography == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'personal' and $page->lvl == 2) { $all_biography_lvl3 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all()->as_array(null, 'id'); $all_biography_lvl4 = ORM::factory('Page')->where('parent_id', 'in', $all_biography_lvl3)->find_all(); $newbiography = false; foreach ($all_biography_lvl4 as $biography_lvl4) { set_time_limit(30); if ($newbiography == false) { $e = explode('_', $biography_lvl4->key); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Biography'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $biography = ORM::factory('Biography')->where('id', 'in', $inlog)->and_where('category_id', '=', $e[1])->find_all()->as_array(null, 'id'); if (count($biography) > 0) { $newbiography = true; } } } } if ($newbiography == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //Книги любые $e = explode('_', $page->key); if ($e[0] == 'books' and isset($e[2])) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); $cats[] = $e[2]; if (count($inlog) > 0) { if (count(Subtool::findinbooks($inlog, $cats)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } // Историческое образование if ($key == 'education' and $page->lvl == 3) { $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all(); if (count($find_child_lvl3) > 0) { $education_lvl3 = false; foreach ($find_child_lvl3 as $child_lvl3) { if ($education_lvl3 == false) { $allsub = array(); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $e = explode('_', $child_lvl3->key); $allsub[] = $e[1]; if (count(Subtool::findinbooks($inlog, $allsub)) > 0) { $education_lvl3 = true; } } } } if ($education_lvl3 == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } if ($key == 'education' and $page->lvl == 2) { $find_child_lvl2 = ORM::factory('Page')->where('parent_id', '=', $sub->category_id)->find_all()->as_array(null, 'id'); $neweducation = false; foreach ($find_child_lvl2 as $child_lvl2) { set_time_limit(30); if ($neweducation == false) { $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $child_lvl2)->find_all(); if (count($find_child_lvl3) > 0) { foreach ($find_child_lvl3 as $child_lvl3) { $allsub = array(); $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $e = explode('_', $child_lvl3->key); $allsub[] = $e[1]; if (count(Subtool::findinbooks($inlog, $allsub)) > 0) { $neweducation = true; } } } } else { $booksfore = ORM::factory('Page', $child_lvl2); //опасный момент $e = explode('_', $booksfore->key); if ($e[0] == 'books' and isset($e[2])) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); $cats[] = $e[2]; if (count($inlog) > 0) { if (count(Subtool::findinbooks($inlog, $cats)) > 0) { $neweducation = true; } } } } } } if ($neweducation == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //Организации образования и науки if ($key == 'institute' and $page->lvl == 3) { set_time_limit(30); $find_child_lvl4 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); if (count($find_child_lvl4->as_array(null, 'id')) > 0) { foreach ($find_child_lvl4 as $child_lvl4) { $find_child_lvl5 = ORM::factory('Page')->where('parent_id', '=', $child_lvl4->id)->find_all()->as_array(null, 'id'); if (count($find_child_lvl5) > 0) { $child_lvl5[] = $find_child_lvl5[0]; } } if (count($child_lvl5) > 0) { $find_organization = ORM::factory('Organization')->where('page_id', 'in', $child_lvl5)->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($find_organization) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } else { $child_lvl4_ids = $find_child_lvl4->as_array(null, 'id'); $find_organization = ORM::factory('Organization')->where('page_id', 'in', $child_lvl4_ids)->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($find_organization) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $page->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } } if ($key == 'institute' and $page->lvl == 2) { $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $newinstitute = false; foreach ($find_child_lvl3 as $child_lvl3) { set_time_limit(30); if ($newinstitute == false) { $find_child_lvl4 = ORM::factory('Page')->where('parent_id', '=', $child_lvl3->id)->find_all(); if (count($find_child_lvl4->as_array(null, 'id')) > 0) { foreach ($find_child_lvl4 as $child_lvl4) { set_time_limit(30); $find_child_lvl5 = ORM::factory('Page')->where('parent_id', '=', $child_lvl4->id)->find_all()->as_array(null, 'id'); if (count($find_child_lvl5) > 0) { $child_lvl5[] = $find_child_lvl5[0]; } } if (count($child_lvl5) > 0) { $find_organization = ORM::factory('Organization')->where('page_id', 'in', $child_lvl5)->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($find_organization) > 0) { $newinstitute = true; } } else { $child_lvl4_ids = $find_child_lvl4->as_array(null, 'id'); $find_organization = ORM::factory('Organization')->where('page_id', 'in', $child_lvl4_ids)->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($find_organization) > 0) { $newinstitute = true; } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $page->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $newinstitute = true; } } } } } if ($newinstitute == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'people' and $page->lvl == 3) { $find_child_lvl4 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all()->as_array(null, 'id'); if (count($find_child_lvl4) > 0) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs = $find_child_lvl4; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $page->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } } if ($key == 'people' and $page->lvl == 2) { $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $newpeople = false; foreach ($find_child_lvl3 as $child_lvl3) { set_time_limit(30); if ($newpeople == false) { $find_child_lvl4 = ORM::factory('Page')->where('parent_id', '=', $child_lvl3->id)->find_all()->as_array(null, 'id'); if (count($find_child_lvl4) > 0) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs = $find_child_lvl4; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $newpeople = true; } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $child_lvl3->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $newpeople = true; } } } } } if ($newpeople == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //публикации if ($key == 'publications' and $page->lvl == 2) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Publication'))->and_where('language', '=', $lang)->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($inlog) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //Электронный журнал "e-history.kz" if ($key == 'metodology' or $key == 'crossstudy' or $key == 'metodicheskie') { $find_childs_lvl4 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $finded_lvl3 = false; foreach ($find_childs_lvl4 as $childs_lvl4) { set_time_limit(30); if ($finded_lvl3 == false) { set_time_limit(30); $find_childs_lvl5 = ORM::factory('Page')->where('parent_id', '=', $childs_lvl4->id)->find_all()->as_array(null, 'id'); if (count($find_childs_lvl5) > 0) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs = $find_childs_lvl5; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $finded_lvl3 = true; } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $childs_lvl4->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $finded_lvl3 = true; } } } } } if ($finded_lvl3 == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'journal_ehistory') { $find_childs_lvl3 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $newehistory = false; foreach ($find_childs_lvl3 as $childs_lvl3) { set_time_limit(30); if ($newehistory == false) { $find_childs_lvl4 = ORM::factory('Page')->where('parent_id', '=', $childs_lvl3->id)->find_all(); $finded_lvl3 = false; foreach ($find_childs_lvl4 as $childs_lvl4) { if ($finded_lvl3 == false) { set_time_limit(30); $find_childs_lvl5 = ORM::factory('Page')->where('parent_id', '=', $childs_lvl4->id)->find_all()->as_array(null, 'id'); if (count($find_childs_lvl5) > 0) { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs = $find_childs_lvl5; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $finded_lvl3 = true; $newehistory = true; } } } else { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Pages_Content'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $allsubs[] = $childs_lvl4->id; if (count(Subtool::findincontents($inlog, $allsubs)) > 0) { $finded_lvl3 = true; $newehistory = true; } } } } } } } if ($newehistory == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } //блок интерактив if ($key == 'debate') { $debates = ORM::factory('Debate')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($debates) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'briefings') { $briefings = ORM::factory('Briefing')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($briefings) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'scorm') { $educations = ORM::factory('Education')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($educations) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'ent') { $ent = ORM::factory('Ent')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($ent) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'interactive') { $interactives = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $newinteractive = false; foreach ($interactives as $child) { set_time_limit(30); if ($newinteractive == false) { $child_key = $child->key; if ($child_key == 'debate') { $debates = ORM::factory('Debate')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($debates) > 0) { $newinteractive = true; } } if ($child_key == 'briefings') { $briefings = ORM::factory('Briefing')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($briefings) > 0) { $newinteractive = true; } } if ($child_key == 'scorm') { $educations = ORM::factory('Education')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($educations) > 0) { $newinteractive = true; } } if ($child_key == 'ent') { $ent = ORM::factory('Ent')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($ent) > 0) { $newinteractive = true; } } } } if ($newinteractive == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'photosets') { $photosets = ORM::factory('Photoset')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($photosets) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'video') { $videos = ORM::factory('Video')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($videos) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'audio') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Audio'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $audios = ORM::factory('Audio')->where('id', 'in', $inlog)->find_all()->as_array(null, 'id'); if (count($audios) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } if ($key == 'infographs') { $infographs = ORM::factory('Infograph')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($infographs) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } if ($key == 'library') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $books = ORM::factory('Book')->where('id', 'in', $inlog)->find_all()->as_array(null, 'id'); if (count($books) > 0) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } } if ($key == 'multimedia') { $find_child_lvl3 = ORM::factory('Page')->where('parent_id', '=', $page->id)->find_all(); $newmultimedia = false; foreach ($find_child_lvl3 as $child_lvl3) { set_time_limit(30); if ($newmultimedia == false) { $child_key = $child_lvl3->key; if ($child_key == 'photosets') { $photosets = ORM::factory('Photoset')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($photosets) > 0) { $newmultimedia = true; } } if ($child_key == 'video') { $videos = ORM::factory('Video')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($videos) > 0) { $newmultimedia = true; } } if ($child_key == 'audio') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Audio'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $audios = ORM::factory('Audio')->where('id', 'in', $inlog)->find_all()->as_array(null, 'id'); if (count($audios) > 0) { $newmultimedia = true; } } } if ($child_key == 'infographs') { $infographs = ORM::factory('Infograph')->where('date', '>', $lastdate)->find_all()->as_array(null, 'id'); if (count($infographs) > 0) { $newmultimedia = true; } } if ($child_key == 'library') { $inlog = ORM::factory('Log')->where(DB::expr('lower(model)'), 'LIKE', strtolower('Model_Book'))->and_where('date', '>', $lastdate)->find_all()->as_array(null, 'content_id'); if (count($inlog) > 0) { $books = ORM::factory('Book')->where('id', 'in', $inlog)->find_all()->as_array(null, 'id'); if (count($books) > 0) { $newmultimedia = true; } } } } } if ($newmultimedia == true) { $links[] = array('link' => URL::media($lang . '/contents/list/' . $sub->category_id), 'title' => $page->name); } } $subupdate = ORM::factory('Subscription', $sub->id); $subupdate->date = date("Y-m-d H:i:s"); $subupdate->save(); } $time = microtime(true) - $start; if (count($links) != 0) { $report_list[] = array('time' => $time, 'user_id' => $user_id); Email::connect(); if ($lang == 'ru' or $lang == 'RU') { Email::View('distribution_ru'); } if ($lang == 'kz' or $lang == 'KZ') { Email::View('distribution_kz'); } if ($lang == 'en' or $lang == 'EN') { Email::View('distribution_en'); } Email::set(array('user' => $user_name, 'period1' => $lastdate, 'period2' => date("Y-m-d H:i:s"), 'unsublink' => Subtool::media('/' . $lang . '/profile/subscription'), 'links' => $links)); set_time_limit(60); Email::send($user_email, array('*****@*****.**', 'e-history.kz'), I18n::get('Обновления на портале Истории Казахстана e-history.kz'), '', true); } } } set_time_limit(60); if (count($report_list) != 0) { Email::connect(); Email::View('successsub'); Email::set(array('message' => 'Все рассылки успешно разослались', 'list' => $report_list)); Email::send('*****@*****.**', array('*****@*****.**', 'e-history.kz'), "Рассылки на истории", '', true); } else { Email::connect(); Email::View('default'); Email::set(array('message' => 'Сегодня никому ничего не отправлено')); Email::send('*****@*****.**', array('*****@*****.**', 'e-history.kz'), "Рассылки на истории", '', true); } }
public function action_new() { $id = (int) $this->request->param('id', 0); $debate = ORM::factory('Debate', $id); if ($debate->loaded() and !$debate->admin_create) { $this->redirect('manage/debate'); } $this->set('debate', $debate); if ($this->request->method() == Request::POST) { $author_email = strtolower(Arr::get($_POST, 'author_email', '')); $opponent_email = strtolower(Arr::get($_POST, 'opponent_email', '')); $author = ORM::factory('User')->where('email', '=', $author_email)->find(); $opponent = ORM::factory('User')->where('email', '=', $opponent_email)->find(); if ($opponent->loaded() && $author->loaded() && $author_email != $opponent_email) { if ($debate->loaded()) { $old_title = $debate->title; $old_description = $debate->description; $old_end_time = $debate->end_time; $old_author = $debate->author_id; $old_opponent = $debate->opponent_id; } else { $debate_create = true; } try { $debate->title = Arr::get($_POST, 'title', ''); $debate->description = Arr::get($_POST, 'description', ''); $debate->lifetime = (int) Arr::get($_POST, 'lifetime', ''); $debate->date = $debate->start_time = date('Y-m-d H:i:s'); $debate->end_time = date('Y-m-d H:i:s', strtotime("+" . $debate->lifetime . " hours", strtotime(date('Y-m-d H:i:s')))); $debate->author_id = $debate->replier_id = $author->id; $debate->author_email = $author_email; $debate->opponent_id = $opponent->id; $debate->opponent_email = $opponent_email; $debate->language = $this->language; $debate->is_public = 1; $debate->admin_create = 1; $debate->save(); if (isset($old_title) && $old_title != $debate->title) { $this->log($debate->id, 'title', $old_title, $debate->title); } if (isset($old_description) && $old_description != $debate->description) { $this->log($debate->id, 'description', $old_description, $debate->description); } if (isset($old_end_time) && $old_end_time != $debate->end_time) { $this->log($debate->id, 'time', $old_end_time, $debate->end_time); } if (isset($old_author) && $old_author != $debate->author_id) { $this->log($debate->id, 'member', $old_author, $debate->author_id); } if (isset($old_opponent) && $old_opponent != $debate->opponent_id) { $this->log($debate->id, 'member', $old_opponent, $debate->opponent_id); } if (isset($debate_create)) { $this->log($debate->id, 'create'); } Message::success(i18n::get('Дебаты сохранены')); $debate_link = Url::site("debate/view/" . $debate->id, true); $ending_tr = "Your opponent was given the right to begin debates"; Email::connect(); Email::View('new_debate'); Email::set(array('author' => $author->username, 'link' => 'e-history.kz', 'theme' => "<a href='" . $debate_link . "'>'" . $debate->title . "'</a>", 'ending' => true, 'ending_tr' => $ending_tr)); Email::send($debate->opponent_email, array('*****@*****.**', 'e-history.kz'), __("Участие в дебатах на тему :theme", array(':theme' => "'" . $debate->title . "'")), '', true); $ending_tr = "You are given the right to begin debates"; Email::connect(); Email::View('new_debate'); Email::set(array('author' => $opponent->username, 'link' => 'e-history.kz', 'theme' => "<a href='" . $debate_link . "'>'" . $debate->title . "'</a>", 'ending' => true, 'ending_tr' => $ending_tr)); Email::send($debate->author_email, array('*****@*****.**', 'e-history.kz'), __("Участие в дебатах на тему :theme", array(':theme' => "'" . $debate->title . "'")), '', true); $this->redirect('manage/debate'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors($e->alias()); $this->set('debate', $_POST); $this->set('errors', $errors); } } else { if (!$author->loaded()) { $errors['author_email'] = true; } if (!$opponent->loaded()) { $errors['opponent_email'] = true; } if ($author_email == $opponent_email) { $errors['members'] = true; } $this->set('debate', $_POST); $this->set('errors', $errors); } } }
public function action_reject() { $id = $this->request->param('id'); $material = ORM::factory('Material', $id); if (!$material->loaded() or $material->status != 2 or $material->is_moderator == 0) { $this->redirect('manage/materials'); } $user_id = $material->user_id; $lang = $material->lang_notice; $user_email = ORM::factory('User', $user_id)->email; $this->set('material', $material); $token = Arr::get($_POST, 'token', false); $return = Arr::get($_POST, 'r', 'manage/materials'); $this->set('return', Url::site($return)); if ($this->request->method() == Request::POST && Security::token() === $token) { $message = Arr::get($_POST, 'message', ''); if ($message != '') { $material->status = 0; $material->mod_message = $message; $material->moderator_id = $this->user->id; $material->save(); $prelang = i18n::lang(); I18n::lang($lang); Email::connect(); Email::View('review_accept_' . $lang); Email::set(array('message' => I18n::get('Редакционной коллегией портала "История Казахстана" было отказано в публикации оставленного вами материала.'))); Email::send($user_email, array('*****@*****.**', 'e-history.kz'), I18n::get('Рассмотрение материала на портале "История Казахстана" e-history.kz'), '', true); I18n::lang($prelang); $this->redirect('manage/materials'); } else { $this->set('message', $message)->set('token', Security::token(true))->set('errors', true); } } else { $this->set('token', Security::token(true)); } }
public function action_reminder() { $errors = NULL; if (!Auth::instance()->logged_in()) { if ($this->request->post()) { if (Captcha::valid($_POST['captcha'])) { $user = ORM::factory('User')->where('username', '=', Arr::get($_POST, 'username', ''))->find(); if ($user->loaded() && $user->network_reg == 0 && empty($user->link_activate)) { $date = date("Y-m-d H:i:s"); $code = md5($date . $user->password); Email::connect(); Email::View('reminder'); Email::set(array('username' => $user->username, 'id' => $code, 'url' => str_replace('/auth/reminder', '', URL::current(true)))); Email::send($user->email, array('*****@*****.**', 'e-history.kz'), "E-history.kz, ссылка для смены пароля.", '', true); $save_code = ORM::factory('User', $user->id); $save_code->link_recovery = $code; $save_code->save(); Message::success('Ссылка для восстановления пароля отправлена на указанный при регистрации адрес электронной почты.'); $this->redirect('/', 301); } else { $errors['login'] = I18n::get("Пользователь с таким логином не зарегистрирован."); } } else { $errors['captcha'] = I18n::get("Неправильно ввели код подтверждения."); } } } $this->set('errors', $errors); }
public function action_register() { $post = $this->post; $username = Security::xss_clean(Arr::get($post, 'login', '')); $email = Security::xss_clean(Arr::get($post, 'email', '')); $password = Security::xss_clean(Arr::get($post, 'password', '')); $password_confirm = Security::xss_clean(Arr::get($post, 'password', '')); $social_token = Security::xss_clean(Arr::get($post, 'token', '')); if (!Auth::instance()->logged_in()) { if (!empty($post) || $social_token != '') { if ($social_token != '') { $s = file_get_contents('http://ulogin.ru/token.php?token=' . $social_token . '&host=' . $_SERVER['HTTP_HOST']); /* узнать как будет выглядеть массив от клиента с данными из соц сети */ $ulogin = json_decode($s, true); //var_dump($ulogin); //$ulogin = Security::xss_clean(Arr::get($post, 'ulogin', '')); $identity = $ulogin['network'] . '_' . $ulogin['uid']; $user = ORM::factory('user')->where('username', '=', $identity)->or_where('email', 'LIKE', '%' . Arr::get($ulogin, 'email', '1NrJH43ksWlrn'))->find(); if (!$user->loaded()) { $pass = strtotime(date("Y-m-d H:i:s")) . $social_token; $role = ORM::factory('Role', 1); $user = ORM::factory('User')->values(array('username' => $identity, 'password' => $pass, 'password_confirm' => $pass, 'email' => $ulogin['network'] . '_' . $ulogin['uid'] . '_' . Arr::get($ulogin, 'email', $identity . '@test.kz'), 'network_reg' => 1))->save(); $user->add('roles', $role); if ($ulogin['network'] != "yandex") { $photo = Storage::instance()->save_social_photo(Arr::get($ulogin, 'photo', ''), $user->pk()); } else { $photo = 0; } ORM::factory('User_Profile')->values(array('user_id' => $user->pk(), 'first_name' => Arr::get($ulogin, 'first_name', ''), 'last_name' => Arr::get($ulogin, 'last_name', ''), 'photo' => $photo, 'phone' => Arr::get($ulogin, 'phone', ''), 'email' => Arr::get($ulogin, 'email', ''), 'location_id' => 0))->save(); //Auth::instance()->force_login($identity); //успешная регистрация $this->data['socialReg'] = true; } else { $this->data['error'] = 'Social user is already registered'; //Auth::instance()->force_login($user->username); //Пользоатель уже существует } } else { $findusername = ORM::factory('User')->where('username', '=', $username)->find_all()->count(); if ($findusername == 0) { $findemail = ORM::factory('User')->where('email', '=', $email)->find_all()->count(); if ($findemail == 0) { $date = date("Y-m-d H:i:s"); $code = md5($date . $password); $user = ORM::factory('User')->values(array('username' => $username, 'email' => $email, 'password' => $password, 'password_confirm' => $password_confirm, 'network_reg' => 0, 'link_activate' => $code)); $user->save(); Email::connect(); Email::View('activate'); Email::set(array('username' => $username, 'id' => $code, 'url' => URL::site('/', true))); Email::send($email, array('*****@*****.**', 'e-history.kz'), "Подтверждение регистрации на сайте E-history.kz", '', true); $this->data[] = true; //Успешная простая регистрация } else { $this->data['error'] = 'Email is already registered'; //такой ящик уже есть } } else { $this->data['error'] = 'Login is already registered'; } //Message::success('На указанный email отправлено письмо со ссылкой на подтверждение регистрации.'); } } } $this->response->body(json_encode($this->data)); }
public function action_show() { $id = (int) $this->request->param('id', 0); $page = (int) $this->request->param('page', 0); $theme = ORM::factory('Forum_Theme', $id); $section = ORM::factory('Forum', $theme->forum_id); if (!$theme->loaded()) { throw new HTTP_Exception_404(); } $notification = ORM::factory('Forum_Notification')->where('user_id', '=', $this->user)->and_where('theme_id', '=', $id)->find(); $messages = $theme->forum_message->where('first_message', '<>', 1)->and_where('companion_id', '=', 0)->order_by('date', 'asc'); $paginate = Paginate::factory($messages)->paginate(NULL, NULL, 4)->render(); $messages = $messages->find_all(); $this->add_cumb('Forum', 'forum'); $this->add_cumb($section->name, 'forum/list/' . $section->id); $this->add_cumb($theme->name, '/'); /* description */ $first_message = $theme->forum_message->where('first_message', '=', 1)->find(); $this->metadata->snippet($first_message->text); $this->set('theme', $theme)->set('page', $page)->set('messages', $messages)->set('notification', $notification->notification)->set('paginate', $paginate); if ($post = $this->request->post()) { if (!$this->user) { throw new HTTP_Exception_404(); } try { $email_notification = Security::xss_clean(Arr::get($post, 'notification', 0)); $message = ORM::factory('Forum_Message'); $message->text = Security::xss_clean(Arr::get($post, 'text', '')); $message->user_id = $this->user->pk(); $message->section_id = $theme->forum_id; $message->theme_id = $id; $message->companion_id = 0; $message->date = date('Y-m-d H:i:s'); $message->save(); if (!empty($email_notification)) { $notification = 1; } else { $notification = 0; } $notification_user = ORM::factory('Forum_Notification')->where('user_id', '=', $this->user->pk())->and_where('theme_id', '=', $id)->find(); if ($notification_user->loaded()) { $notification_user->notification = $notification; $notification_user->update(); } else { $notification_user->user_id = $this->user->pk(); $notification_user->theme_id = $id; $notification_user->notification = $notification; $notification_user->save(); } /* чтобы при добавлении нового сообщения нормально отработала пагинация */ $messages = $theme->forum_message->where('first_message', '<>', 1)->order_by('date', 'asc'); $paginate = Paginate::factory($messages)->paginate(NULL, NULL, 4); $last_page = $paginate->page_count(); $link = '/' . $this->language . '/forum/show/' . $id . '/page-' . $last_page; /* email уведомление подписанным на тему пользователям */ $users = ORM::factory('User')->join('forum_notifications', 'LEFT')->on('user.id', '=', 'forum_notifications.user_id')->where('forum_notifications.notification', '=', '1')->and_where('forum_notifications.theme_id', '=', $id)->and_where('forum_notifications.user_id', '<>', $this->user)->find_all(); if ($users->count() > 0) { Email::connect(); Email::View('forum_notification'); foreach ($users as $user) { Email::set(array('id' => $user->id, 'receivername' => $user->show_name(), 'sendername' => $this->user->show_name(), 'url' => $link)); Email::send($user->email, array('*****@*****.**', 'e-history.kz'), "Ответ в теме " . $theme->name, '', true); } } $this->redirect('forum/show/' . $id . '/page-' . $last_page, 301); } catch (ORM_Validation_Exception $e) { $errors = $e->errors($e->alias()); $this->set('errors', $errors); $this->set('message', $_POST); } } }