function descriptionAction() { $this->view->activeTab = 'Campaigns'; $consumer = $this->_currentUser; $id = (int) $this->_request->getParam('id'); //precampaignsurvey的css使用的是layout_survey $this->_helper->layout->setLayout("layout_survey"); if ($id > 0) { $this->view->id = $id; $campaignModel = new Campaign(); $this->view->campaign = $campaignModel->fetchRow('id=' . $id); } else { //TODO not found return; } //whether participate in the campaign 2011-05-19 ham.bao $campaigninvitationModel = new CampaignInvitation(); $campaigninvitation = $campaigninvitationModel->fetchRow('campaign_id = ' . $id . ' and consumer_id' . ' =' . $consumer->id); if ($campaigninvitation == null) { $this->_helper->redirector('index', 'home'); } $this->view->title = $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->campaign->name; //count days left before expire $expire_date = $this->view->campaign["expire_date"]; $expire_date_year = substr($expire_date, 0, 4); $expire_date_month = substr($expire_date, 5, 2); $expire_date_day = substr($expire_date, 8, 2); $expire_date_hour = substr($expire_date, 11, 2); $expire_date_min = substr($expire_date, 14, 2); $expire_date_sec = substr($expire_date, 17, 2); $expire = mktime($expire_date_hour, $expire_date_min, $expire_date_sec, $expire_date_month, $expire_date_day, $expire_date_year); $currentTime = mktime(); $this->view->dayCount = round(($expire - $currentTime) / 3600 / 24); if ($this->view->dayCount <= 0) { $this->view->dayCount = 0; } //count campaign points $db = Zend_Registry::get('db'); $select = $db->select(); $select->from('reward_point_transaction_record', 'sum(reward_point_transaction_record.point_amount) AS point, '); $select->where('reward_point_transaction_record.consumer_id=?', $consumer->id); $select->where('report.campaign_id =?', $id); $select->join('report', 'reward_point_transaction_record.id = report.reward_point_transaction_record_id'); $select->group('report.campaign_id'); $this->view->campaignPoint = $db->fetchOne($select); if (empty($this->view->campaignPoint) || $this->view->campaignPoint == '') { $this->view->campaignPoint = 0; } $select2 = $db->select(); $select2->from('report', 'count(*)')->where('report.consumer_id = ? ', $consumer->id)->where('report.campaign_id = ? ', $id); $this->view->reportCount = $db->fetchOne($select2); $langNamespace = new Zend_Session_Namespace('Lang'); $this->view->lang = $langNamespace->lang; //url report //2011 ham.bao multi urlreport $urlReportModel = new UrlReport(); $urlReportData = $urlReportModel->fetchAll('campaign_id = ' . $id . ' and consumer_id = ' . $consumer->id, 'create_date desc'); $this->view->urlReport = $urlReportData->toArray(); //print_r($this->view->urlReport);die; }
function adminsaveurlreportstateAction() { $type = $this->_request->getParam('type'); $db = Zend_Registry::get('db'); if ($type == 'reportState') { $idStr = $this->_request->getParam('reportids'); $idStrArray = explode(',', $idStr); $reportIdArray = array(); $i = 0; $config = Zend_Registry::get('config'); $smtpSender = new Zend_Mail_Transport_Smtp($config->smtp->report->mail->server, array('username' => $config->smtp->report->mail->username, 'password' => $config->smtp->report->mail->password, 'auth' => $config->smtp->report->mail->auth, 'ssl' => $config->smtp->report->mail->ssl, 'port' => $config->smtp->report->mail->port)); // $smtpSender = new Zend_Mail_Transport_Smtp( // 'smtp.163.com',array( // 'username'=>'*****@*****.**', // 'password'=>'19990402', // 'auth'=>'login')); Zend_Mail::setDefaultTransport($smtpSender); foreach ($idStrArray as $idAndState) { if ($idAndState == '') { continue; } $idAndStateArray = explode('@', $idAndState); if ($idAndStateArray[1] == 'NEW') { continue; } if ($idAndStateArray[1] == 'APPROVED') { $urlreportModel = new UrlReport(); $row = $urlreportModel->fetchRow('id = ' . $idAndStateArray[0]); if ($row->state != 'NEW') { continue; } $row->state = $idAndStateArray[1]; if ($row->reward_point_transaction_record_id == null || $row->reward_point_transaction_record_id == '') { $rewardModel = new RewardPointTransactionRecord(); $reward = $rewardModel->createRow(); $reward->consumer_id = $idAndStateArray[2]; $reward->date = date("Y-m-d H:i:s"); $reward->transaction_id = 8; $reward->point_amount = 300; $row->reward_point_transaction_record_id = $reward->save(); } else { $rewardModel = new RewardPointTransactionRecord(); $reward = $rewardModel->fetchRow('id = ' . $row->reward_point_transaction_record_id); if ($reward != null) { $reward->date = date("Y-m-d H:i:s"); $reward->point_amount = 300; $reward->save(); } } $row->save(); //2011-05-13 change the rank of consumer $rankModel = new Rank(); $rankModel->changeConsumerRank($idAndStateArray[1]); } if ($idAndStateArray[1] == 'UNAPPROVED') { $urlreportModel = new UrlReport(); $row = $urlreportModel->fetchRow('id = ' . $idAndStateArray[0]); if ($row == null) { continue; } if ($row->reward_point_transaction_record_id != null && $row->reward_point_transaction_record_id != '') { $rewardModel = new RewardPointTransactionRecord(); $reward = $rewardModel->fetchRow('id = ' . $row->reward_point_transaction_record_id); if ($reward != null) { $db2 = $rewardModel->getAdapter(); $where = $db2->quoteInto('id = ?', $row->reward_point_transaction_record_id); $rows_affected = $rewardModel->delete($where); } } $db2 = $urlreportModel->getAdapter(); $where = $db2->quoteInto('id = ?', $idAndStateArray[0]); $rows_affected = $urlreportModel->delete($where); } $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow('id = ' . $idAndStateArray[2]); //send mail... if ($consumer->email == '') { continue; } $mail = new Zend_Mail('utf-8'); if ($consumer->language_pref != null && $consumer->language_pref == 'en') { $emailSubject = $this->view->translate('Admin_Reply_WOM_URLReport_Subject_en'); $emailBody = $this->view->translate('Admin_Reply_WOM_URLReport_Body_en'); } else { $emailSubject = $this->view->translate('Admin_Reply_WOM_URLReport_Subject_zh'); $emailBody = $this->view->translate('Admin_Reply_WOM_URLReport_Body_zh'); } $stringChange = array('?USERNAME?' => $consumer->name, '?YOURSTORY?' => $row->url, '?MYRESPONSE?' => $idAndStateArray[3]); $emailBody = strtr($emailBody, $stringChange); $langNamespace = new Zend_Session_Namespace('Lang'); if ($langNamespace->lang == 'en' || $langNamespace->lang == 'EN') { $mail->setSubject($emailSubject); } else { $mail->setSubject("=?UTF-8?B?" . base64_encode($emailSubject) . "?="); } $mail->setBodyText($emailBody); $mail->addTo($consumer->email); $mail->setFrom($config->smtp->report->mail->username, $this->view->translate('Wildfire')); // $mail->setFrom('*****@*****.**',$this->view->translate('Wildfire')); $mail->send(); // save email $urlreportreplyModel = new UrlReportReply(); $urlreportreply = $urlreportreplyModel->createRow(); $urlreportreply->date = date("Y-m-d H:i:s"); $urlreportreply->subject = $emailSubject; $urlreportreply->content = $idAndStateArray[3]; $urlreportreply->from = $config->smtp->report->mail->username; $urlreportreply->to = $consumer->email; $urlreportreply->url_report_id = $row->id; //2011-04-08 ham.bao separate the sessions with admin $urlreportreply->admin_id = $this->_currentAdmin->id; $urlreportreply->save(); } } }
function indexAction() { $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("Index_HOME"); $this->view->activeTab = 'Home'; $consumer = $this->_currentUser; $this->view->currentUser = $consumer; $langNamespace = new Zend_Session_Namespace('Lang'); $this->view->lang = $langNamespace->lang; $currentTime = date("Y-m-d H:i:s"); // save language pref $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow('id = ' . $this->_currentUser->id); $consumer->language_pref = $langNamespace->lang; $consumer->save(); $db = Zend_Registry::get('db'); //get badges of consumer $badgeModel = new ConsumerBadge(); $badges = $badgeModel->fetchAll("consumer = " . $consumer->id); $this->view->badges = $badges; // active campaigns $select = $db->select(); $select->from('campaign', '*'); $select->join('campaign_invitation', 'campaign.id = campaign_invitation.campaign_id'); $select->join('campaign_participation', 'campaign_invitation.id = campaign_participation.campaign_invitation_id', 'accept_date'); //$select->joinLeft('url_report','url_report.campaign_id = campaign.id and url_report.consumer_id = campaign_invitation.consumer_id ',array('url', 'state as url_state')); $select->where('campaign_invitation.consumer_id = ?', $consumer->id); $select->where('campaign.expire_date > ?', $currentTime); $select->where('campaign_participation.state != "COMPLETED" '); //$select->where('campaign.type = "campaign"'); //url report $url_report = new UrlReport(); $url_reportData = $url_report->fetchAll('consumer_id=' . $consumer->id, 'create_date desc'); $this->view->urlreport = $url_reportData->toArray(); //print_r($this->view->urlreport);die; $select->order('campaign.create_date desc'); $this->view->activeCampaigns = $db->fetchAll($select); // active mission $select = $db->select(); $select->from('campaign', 'campaign.*'); $select->join('campaign_invitation', 'campaign.id = campaign_invitation.campaign_id' . ' and campaign_invitation.consumer_id = ' . $consumer->id, 'campaign_id'); $select->joinLeft('campaign_participation', 'campaign_invitation.id = campaign_participation.campaign_invitation_id', 'accept_date'); $select->where('campaign.expire_date > ?', $currentTime); $select->where('campaign.type = "mission" and campaign.public = "0"'); $select->order('campaign.create_date desc'); $this->view->activeMissions = $db->fetchAll($select); //var_dump($this->view->activeMissions);die; //public missions $select = $db->select(); $select->from('campaign', 'campaign.*'); $select->where('campaign.expire_date > ?', $currentTime); $select->where('campaign.type = "mission" and campaign.public = "1"'); $select->order('campaign.create_date desc'); $this->view->publicMissions = $db->fetchAll($select); //var_dump($this->view->activeMissions);die; $selectImageReportsForCampaign = $db->select(); $selectImageReportsForCampaign->from('image_report', array('image_report.id', 'campaign_id', 'thumb_width', 'thumb_height', 'create_date', 'state')); $selectImageReportsForCampaign->joinLeft('reward_point_transaction_record', 'image_report.reward_point_transaction_record_id = reward_point_transaction_record.id', 'point_amount'); $selectImageReportsForCampaign->where('image_report.consumer_id = ?', $this->_currentUser->id); $selectImageReportsForCampaign->order('image_report.create_date desc'); // $this->view->activeImageReportsForCampaign = $db->fetchAll($selectImageReportsForCampaign); // Zend_Debug::Dump($this->view->activeImageReportsForCampaign); $campaignId = 0; $activeImageReportsForCampaign = array(); foreach ($db->fetchAll($selectImageReportsForCampaign) as $imageReport) { $campaignId = $imageReport['campaign_id']; if (array_key_exists($campaignId, $activeImageReportsForCampaign)) { array_push($activeImageReportsForCampaign[$campaignId], $imageReport); } else { $activeImageReportsForCampaign[$campaignId] = array($imageReport); } } $this->view->activeImageReportsForCampaign = $activeImageReportsForCampaign; $selectAllCampaignReports = $db->select(); $selectAllCampaignReports->from('report', "*")->joinLeft('reward_point_transaction_record', 'reward_point_transaction_record.id = report.reward_point_transaction_record_id', 'point_amount')->where('reward_point_transaction_record.point_amount > 0 or report.state="NEW"')->where('report.consumer_id = ?', $consumer->id); $selectApprovedCampaignReports = $db->select(); $selectApprovedCampaignReports->from('report', "id")->where('report.consumer_id = ?', $consumer->id)->where('report.reward_point_transaction_record_id is not null')->where('reward_point_transaction_record.point_amount > 0')->join('reward_point_transaction_record', 'reward_point_transaction_record.id = report.reward_point_transaction_record_id', 'point_amount'); if (count($this->view->activeCampaigns) > 0) { // get all reports of the first active campaigns // create where clause $activeCampaignId = "("; foreach ($this->view->activeCampaigns as $campaign) { $activeCampaignId .= $campaign['campaign_id'] . ","; } $activeCampaignId = substr($activeCampaignId, 0, strlen($activeCampaignId) - 1); $activeCampaignId .= ")"; $selectAllCampaignReports->where('report.campaign_id in ' . $activeCampaignId); $selectApprovedCampaignReports->where('report.campaign_id in ' . $activeCampaignId); } $this->view->allCampaignReports = $db->fetchAll($selectAllCampaignReports); $approvedCampaignReports = $db->fetchAll($selectApprovedCampaignReports); $this->view->approvedCampaignReportPoint = array(); foreach ($approvedCampaignReports as $approvedCampaignReport) { $this->view->approvedCampaignReportPoint[$approvedCampaignReport['id']] = $approvedCampaignReport['point_amount']; } // total points $this->view->totalPoints = $db->fetchOne("SELECT sum(point_amount) FROM reward_point_transaction_record WHERE transaction_id!=4 and consumer_id = :temp", array('temp' => $consumer->id)); if (empty($this->view->totalPoints)) { $this->view->totalPoints = 0; } //redeem points 在本日之前的30天内的积分不可用, $today = date("Y-m-d", time()); $this->view->redeemPoints = $db->fetchOne("SELECT sum(point_amount) FROM reward_point_transaction_record WHERE (consumer_id = :temp and date <:temp2) or (consumer_id = :temp and date >=:temp2 and transaction_id=4) ", array('temp' => $consumer->id, 'temp2' => date("Y-m-d", strtotime("{$today} -30 day")))); if (empty($this->view->redeemPoints)) { $this->view->redeemPoints = 0; } // new points 30天以内的积分 $this->view->newPoints = $db->fetchOne("SELECT sum(point_amount) FROM reward_point_transaction_record WHERE (consumer_id = :temp and date >=:temp2 and transaction_id!=4) ", array('temp' => $consumer->id, 'temp2' => date("Y-m-d", strtotime("{$today} -30 day")))); if (empty($this->view->newPoints)) { $this->view->newPoints = 0; } //get polls // $profileSurveyModel = new ProfileSurvey(); // $this->view->surveys = $profileSurveyModel->fetchAll('state = "ACTIVE"', 'id DESC', null, null); $select_profilesurvey = $db->select(); $select_profilesurvey->from('profile_survey', '*'); $select_profilesurvey->joinLeft('profilesurvey_invitation', 'profilesurvey_invitation.profile_id = profile_survey.id and profilesurvey_invitation.consumer_id=' . $consumer->id, array('id as invitaitonId', 'consumer_id')); $select_profilesurvey->where('profile_survey.state = "ACTIVE"'); $this->view->surveys = $db->fetchAll($select_profilesurvey); //var_dump($this->view->surveys);die; $select2 = $db->select(); $select2->from('poll_participation', 'poll_id'); $select2->where('poll_participation.consumer_id = ?', $consumer->id)->order('poll_participation.date DESC'); $this->view->completedPolls = $db->fetchAll($select2); // get invitation // add expire_date by Bruce.Liu $select3 = $db->select(); $select3->from('campaign_invitation', '*'); $select3->join('campaign', 'campaign.id = campaign_invitation.campaign_id ', array('campaign.id', 'pre_campaign_survey', 'name', 'type', 'product_name', 'simple_description', 'invitation_description', 'invitation_description2', 'campaign.total')); $select3->where('campaign_invitation.consumer_id = ?', $this->_currentUser->id); $select3->where('campaign_invitation.state = ?', 'NEW'); $select3->where('campaign.expire_date > ?', $currentTime); $select3->order('campaign_invitation.create_date DESC'); $recentInvitationTotalArray = $db->fetchAll($select3); // add logic campare total and campaign_partation number 2013-09-16 // 取到当前被邀请的活动 比较 当前活动的参与人数和当前活动的最高参加人数 $recentInvitationTotalArrayNew = array(); $select_participation_sql_rs = array(); foreach ($recentInvitationTotalArray as $recentInvitationTotal) { $select_participation_sql = $db->select(); $select_participation_sql->from('campaign_invitation', '*'); $select_participation_sql->join('campaign_participation', 'campaign_invitation.id = campaign_participation.campaign_invitation_id'); $select_participation_sql->where('campaign_invitation.state = "ACCEPTED" '); $select_participation_sql->where('campaign_invitation.campaign_id = ' . $recentInvitationTotal['id']); $select_participation_sql_rs = $db->fetchAll($select_participation_sql); if (intval($recentInvitationTotal['total']) > count($select_participation_sql_rs)) { array_push($recentInvitationTotalArrayNew, $recentInvitationTotal); } } $this->view->recentInvitation = $recentInvitationTotalArrayNew; $this->view->allInvitations = $this->view->recentInvitation; // $this->view->recentInvitation = $db->fetchRow($select3); // $this->view->allInvitations = $db->fetchAll($select3); //print_r($this->view->allInvitations);die; // Zend_Debug::dump($this->view->allInvitations);die(); //post-campaign survey popup // add expire_date by Bruce.Liu $select4 = $db->select(); $select4->from('campaign_participation', '*'); $select4->join('campaign_invitation', 'campaign_participation.campaign_invitation_id = campaign_invitation.id'); $select4->join('campaign', 'campaign.id = campaign_invitation.campaign_id'); $select4->where('campaign_invitation.consumer_id = ?', $this->_currentUser->id); $select4->where('campaign.expire_date > ?', $currentTime); $select4->where('campaign_participation.state = ?', 'FINISHING'); $select4->order('campaign_invitation.create_date DESC'); $this->view->postCampaignNotification = $db->fetchRow($select4); // shut down pop-up $appspace = new Zend_Session_Namespace('application'); if (!isset($appspace->popup) || $appspace->popup) { $this->view->popup = true; $appspace->popup = false; } // consumer info bar session $consumerExtraInfo = new Zend_Session_Namespace('consumerExtraInfo'); if (!isset($consumerExtraInfo->data)) { // The username and email are 20 points $count = 20; $consumerinfoArray = $consumer->toArray(); for ($i = 0; $i < count($consumerinfoArray); $i++) { $temp = each($consumerinfoArray); // Address1, phone, city and recipients_name is 5 points each if ($temp['key'] == 'address1' || $temp['key'] == 'phone' || $temp['key'] == 'city' || $temp['key'] == 'recipients_name') { if ($temp['value'] != null && $temp['value'] != '') { $count += 5; } } else { continue; } } $consumerextraModel = new ConsumerExtraInfo(); $consumerextra = $consumerextraModel->fetchRow('consumer_id = ' . $this->_currentUser->id); if ($consumerextra != null) { $extrainfoArray = $consumerextra->toArray(); $inc = round(60 / (count($extrainfoArray) - 3), 1); for ($i = 0; $i < count($extrainfoArray); $i++) { $temp = each($extrainfoArray); // Ignore birth year of children if ($temp['key'] == 'id' || $temp['key'] == 'consumer_id' || $temp['key'] == 'children_birth_year') { continue; } else { if ($temp['value'] != null && $temp['value'] != '') { $count += $inc; } } } $count = floor($count); $count = $count + ($count % 5 == 0 ? 0 : 5 - $count % 5) > 100 ? 100 : $count + ($count % 5 == 0 ? 0 : 5 - $count % 5); } $consumerExtraInfo->data = $count; } $this->view->consumerextrainfo = $consumerExtraInfo->data; //consumer information $select = $db->select(); $select->from('consumer', '*'); $select->joinLeft('rank', 'consumer.rank = rank.id', array('name as rname')); $select->where('consumer.id = ?', $this->_currentUser->id); $this->view->consumer = $db->fetchAll($select); //var_dump($this->view->consumer);die; }