Exemple #1
0
 public function show()
 {
     pc_base::load_sys_class('form', '', 0);
     $M = getcache('ask', 'commons');
     $M = $M[1];
     $_username = param::get_cookie('_username', L('phpcms_friends'));
     $_userid = param::get_cookie('_userid');
     $r_m = $this->db_m->get_one(array('userid' => $_userid, 'siteid' => SITEID));
     $_point = $r_m['point'];
     $id = intval($_GET['id']);
     if (!$id) {
         showmessage(L('illegal_parameters'), HTTP_REFERER);
     }
     $array = array();
     $a = $this->db->get_one(array('askid' => $id, 'siteid' => SITEID));
     $posts_table_name = $this->db2->posts_table($a['catid']);
     $this->db2->table_name = $posts_table_name;
     if (!$this->db2->table_exists(str_replace($this->db2->db_tablepre, '', $posts_table_name))) {
         showmessage(L('info_does_not_exists'), HTTP_REFERER);
     }
     $result = $this->db2->select("askid={$id} AND status>2 AND siteid=" . SITEID, '*');
     foreach ($result as $r) {
         if ($r['isask']) {
             $arr = $this->db->get_one(array('askid' => $id, 'siteid' => SITEID));
             $r['title'] = $arr['title'];
             $r['reward'] = $arr['reward'];
             $r['status'] = $arr['status'];
             $r['answercount'] = $arr['answercount'];
             $r['flag'] = $arr['flag'];
             $r['endtime'] = $arr['endtime'];
             $r['catid'] = $arr['catid'];
             $r['hits'] = $arr['hits'];
             $r['anonymity'] = $arr['anonymity'];
             $rs['keywords'] = $arr['keywords'];
             $r['keywords'] = explode(' ', $arr['keywords']);
             if (SYS_TIME > $r['endtime'] && !$arr['ischeck']) {
                 $this->db->update(array('ischeck' => '1'), array('askid' => $id));
                 $this->db->update(array('flag' => '3'), 'askid=' . $id . ' AND answercount>1');
                 $this->db2->update(array('candidate' => '1'), array('askid' => $id));
                 $this->db_credit->update($arr['userid'], $arr['username'], $M['del_day15_credit'], 0);
                 pc_base::load_app_class('spend', 'pay', 0);
                 spend::point($M['del_day15_credit'], L('ask_15days_no_deal_with'), $arr['userid'], $arr['username'], '', '', $flag);
             }
         }
         $userids[] = $r['userid'];
         $array[] = $r;
     }
     if ($userids) {
         $userids = implode(',', $userids);
         $data = $this->db_m->select("userid IN ({$userids}) AND siteid=" . SITEID, '*');
         foreach ($data as $r) {
             $userinfo[$r['userid']]['actortype'] = $r['actortype'];
             $userinfo[$r['userid']]['point'] = $r['point'];
         }
         foreach ($array as $arr) {
             $arr['actortype'] = $userinfo[$arr['userid']]['actortype'];
             $arr['point'] = $userinfo[$arr['userid']]['point'];
             $_array[] = $arr;
         }
         $array = $_array;
     } else {
         $array = $array;
     }
     if ($array) {
         $have_answer = false;
         foreach ($array as $k => $v) {
             if ($v['isask']) {
                 $title = $v['title'];
                 $message = $this->M[1]['use_editor'] ? $v['message'] : trim_textarea($v['message']);
                 $reward = $v['reward'];
                 $userid = $v['userid'];
                 $username = $v['username'];
                 $nickname = get_nickname($v['userid']);
                 $status = $v['status'];
                 $hits = $v['hits'];
                 $flag = $v['flag'];
                 $addtime = $v['addtime'];
                 $actor = actor($v['actortype'], $v['point']);
                 $answercount = $v['answercount'];
                 $result = count_down($v['endtime']);
                 $day = $result[0];
                 $hour = $result[1];
                 $minute = $result[2];
                 $catid = $v['catid'];
                 $anonymity = $v['anonymity'];
                 $keywords = $v['keywords'];
             } elseif ($v['optimal']) {
                 $best_answer_pid = $v['pid'];
                 $best_answer_vote_1 = $v['best_answer_vote_1'];
                 $best_answer_vote_2 = $v['best_answer_vote_2'];
                 $totalnum = $best_answer_vote_1 + $best_answer_vote_2;
                 $best_answer_vote_1_per = round($best_answer_vote_1 / $totalnum * 100, 1) . "%";
                 $best_answer_vote_2_per = round($best_answer_vote_2 / $totalnum * 100, 1) . "%";
                 $solvetime = $v['solvetime'];
                 $answer = $v['message'];
                 $answertime = $v['addtime'];
                 $answer = trim_textarea($v['message']);
                 $optimail_username = $v['username'];
                 $optimail_userid = $v['userid'];
                 $optimail_nickname = get_nickname($v['userid']);
                 $optimal_actor = actor($v['actortype'], $v['point']);
             } else {
                 if ($v['userid'] == $_userid) {
                     $have_answer = true;
                 }
                 $infos[$k]['pid'] = $v['pid'];
                 $infos[$k]['userid'] = $v['userid'];
                 $infos[$k]['username'] = $v['username'];
                 $infos[$k]['nickname'] = get_nickname($v['userid']);
                 $infos[$k]['addtime'] = $v['addtime'];
                 $infos[$k]['candidate'] = $v['candidate'];
                 $infos[$k]['anonymity'] = $v['anonymity'];
                 $infos[$k]['actor'] = actor($v['actortype'], $v['point']);
                 $infos[$k]['message'] = $this->M[1]['use_editor'] ? $v['message'] : trim_textarea($v['message']);
             }
         }
         if ($v['optimal']) {
             $answercount = $answercount - 1;
         }
         if ($userid == $_userid) {
             $isask = 1;
         } else {
             $isask = 0;
         }
         if (isset($action) && $action == 'vote') {
             if ($flag == 1) {
                 exit;
             }
             $tpl = 'vote';
         } else {
             $tpl = 'show';
         }
         if ($status == 1) {
             showmessage(L('info_does_not_exists'), HTTP_REFERER);
         }
         if ($userid != $_userid) {
             $this->db->update(array('hits' => '+=1'), array('askid' => $id));
         }
         $description = $answer ? str_cut($answer, '200') : str_cut($message, '200');
         $SEO = seo(SITEID, $catid, $title, $description, $seo_keywords);
         include template('ask', $tpl);
     } else {
         showmessage(L('info_does_not_exists'), HTTP_REFERER);
     }
 }
Exemple #2
0
 public function view_ask()
 {
     $_GET['askid'] = intval($_GET['askid']);
     $array = $this->show($_GET['askid']);
     $CATEGORYS = getcache('category_ask_' . $this->get_siteid(), 'commons');
     if ($array) {
         $have_answer = false;
         foreach ($array as $k => $v) {
             if ($v['isask']) {
                 $title = $v['title'];
                 $message = $M['use_editor'] ? $v['message'] : trim_textarea($v['message']);
                 $reward = $v['reward'];
                 $userid = $v['userid'];
                 $username = $v['username'];
                 $status = $v['status'];
                 $flag = $v['flag'];
                 $addtime = $v['addtime'];
                 $actor = actor($v['actortype'], $v['point']);
                 $answercount = $v['answercount'];
                 $result = count_down($v['endtime']);
                 $day = $result[0];
                 $hour = $result[1];
                 $minute = $result[2];
                 $catid = $v['catid'];
                 $anonymity = $v['anonymity'];
             } elseif ($v['optimal']) {
                 $solvetime = $v['solvetime'];
                 $answer = $v['message'];
                 $answertime = $v['addtime'];
                 $answer = $v['message'];
                 $optimail_username = $v['username'];
                 $optimal_actor = actor($v['actortype'], $v['point']);
             } else {
                 if ($v['userid'] == $_userid) {
                     $have_answer = true;
                 }
                 $infos[$k]['pid'] = $v['pid'];
                 $infos[$k]['userid'] = $v['userid'];
                 $infos[$k]['username'] = $v['username'];
                 $infos[$k]['addtime'] = $v['addtime'];
                 $infos[$k]['candidate'] = $v['candidate'];
                 $infos[$k]['anonymity'] = $v['anonymity'];
                 $infos[$k]['actor'] = actor($v['actortype'], $v['point']);
                 $infos[$k]['message'] = $M['use_editor'] ? $v['message'] : trim_textarea($v['message']);
             }
         }
         if ($v['optimal']) {
             $answercount = $answercount - 1;
         }
         if ($userid == $_userid) {
             $isask = 1;
         } else {
             $isask = 0;
         }
         if (isset($action) && $action == 'vote') {
             if ($flag == 1) {
                 exit;
             }
             $tpl = 'vote';
         } else {
             $tpl = 'show';
         }
         include $this->admin_tpl('ask_view');
     }
 }