function ajaxeditAction() { $this->_helper->layout->disableLayout(); $uid = $this->_request->getParam('uid'); $postData = $this->_request->getPost(); $consumerModel = new Consumer(); $consumerExtraModel = new ConsumerExtraInfo(); if ($postData['field'] == "birthdate" || $postData['field'] == "education" || $postData['field'] == "have_children" || $postData['field'] == "children_birth_year" || $postData['field'] == "income") { $consumerExtraModel->update(array($postData['field'] => $postData['value']), 'consumer_id = ' . $uid); } else { $consumerModel->update(array($postData['field'] => $postData['value']), 'id = ' . $uid); } $this->_helper->json(""); }
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; }
function adminlistAction() { $this->_helper->layout->setLayout("layout_admin"); $request = $this->getRequest(); $db = Zend_Registry::get('db'); // get: show current plan if (!$request->isPost()) { $plan_id = $request->getParam('plan_id'); // get spark's telephone log $telephoneLogModel = new TelephoneLog(); $messageArray = $this->_flashMessenger->getMessages(); if ($messageArray != null) { // show pre page if ($messageArray[0][0] == 'preView') { $telephoneLog = $telephoneLogModel->fetchRow("id < " . $messageArray[0][1] . " and plan_id = " . $plan_id, 'id desc'); } // show first call back page if ($messageArray[0][0] == 'firstcallbackView') { $telephoneLog = $telephoneLogModel->fetchRow("busy = 1 and plan_id = " . $plan_id); } // show pre call back page if ($messageArray[0][0] == 'precallbackView') { $telephoneLog = $telephoneLogModel->fetchRow("id < " . $messageArray[0][1] . " and busy = 1 and plan_id = " . $plan_id, 'id desc'); } //show next call back page if ($messageArray[0][0] == 'nextcallbackView') { $telephoneLog = $telephoneLogModel->fetchRow("id > " . $messageArray[0][1] . " and busy = 1 and plan_id = " . $plan_id); } } if (!isset($telephoneLog)) { //show the next unhandled page $telephoneLog = $telephoneLogModel->fetchRow("state = 'NEW' and plan_id = " . $plan_id); } if (!isset($telephoneLog)) { //if plan is finished, show the first page $telephoneLog = $telephoneLogModel->fetchRow("plan_id = " . $plan_id); } if (isset($telephoneLog)) { $selectTag = $db->select(); $selectTag->from('telephone_log_tag', 'tag_id')->where('telephone_log_id = ?', $telephoneLog->id); $selectedTags = $db->fetchAll($selectTag); $this->view->selectedTagsArray = array(); foreach ($selectedTags as $tag) { $this->view->selectedTagsArray[$tag['tag_id']] = '1'; } } $consumer_id = $telephoneLog->consumer_id; $campaign = new Campaign(); $order = "expire_date desc"; $this->view->campaigns = $campaign->fetchAll(null, $order, null, null); $this->view->plan_id = $plan_id; $this->view->telephoneLog_id = $telephoneLog->id; $this->view->telephoneLog = $telephoneLog; // post: create new plan } else { $formData = $request->getPost(); $sql = $formData['sql']; if ($sql == '' || $sql == null) { return; } else { $sql = 'select consumer.* ' . $sql; } $type = $formData['type']; $content = $formData['content']; //1.execute sql $db = Zend_Registry::get('db'); $result = $db->query($sql); $consumers = $result->fetchAll(); //2.create new telephone plan $telephonePlanModel = new TelephonePlan(); $row = $telephonePlanModel->createRow(); $row->sql = $sql; $row->type = $type; $row->total_consumers = count($consumers); $row->content = $content; //2011-04-08 ham.bao separate the sessions with admin $row->admin_id = $this->_currentAdmin->id; $row->edit_time = date("Y-m-d H:i:s"); $plan_id = $row->save(); //3.create new telephone logs $db = Zend_Registry::get('db'); $result = $db->query($sql); $consumers = $result->fetchAll(); $telephoneLogModel = new TelephoneLog(); $temp = 1; foreach ($consumers as $row) { $newlog = $telephoneLogModel->createRow(); $newlog->consumer_id = $row['id']; //2011-04-08 ham.bao separate the sessions with admin $newlog->admin_id = $this->_currentAdmin->id; $newlog->state = 'New'; $newlog->plan_id = $plan_id; $newlog->edit_time = date("Y-m-d H:i:s"); if ($temp == 1) { $telephoneLog_id = $newlog->save(); $temp = 0; } else { $newlog->save(); } } $consumer_id = $consumers[0]['id']; $this->view->plan_id = $plan_id; $this->view->telephoneLog_id = $telephoneLog_id; $this->view->offset = 0; } // get spark's info $consumerModel = new Consumer(); $this->view->consumerBaseInfo = $consumerModel->fetchRow('id = ' . $consumer_id); $consumerExtraInfoModel = new ConsumerExtraInfo(); $this->view->consumerExtraInfo = $consumerExtraInfoModel->fetchRow('consumer_id = ' . $consumer_id); $this->view->gender = isset($this->consumerExtraInfo) && isset($this->consumerExtraInfo->gender) ? $this->consumerExtraInfo->gender : ""; $consumerLogModel = new Log(); $this->view->consumerLog = $consumerLogModel->fetchRow('consumer_id = ' . $consumer_id, 'date desc'); $selectTotalReport = $db->select(); $selectTotalReport->from('report', 'count(*)')->where('consumer_id = ?', $consumer_id); $this->view->totalReport = $db->fetchOne($selectTotalReport); $selectTotalCampaign = $db->select(); $selectTotalCampaign->from('campaign_invitation', null)->join('campaign', 'campaign.id = campaign_invitation.campaign_id', 'name')->where('consumer_id = ?', $consumer_id)->where("state = 'ACCEPTED'"); $this->view->totalCampaigns = $db->fetchAll($selectTotalCampaign); //tag for telephone $select = $db->select(); $select->from('tags', array('name as key', 'id as tag_id'))->where("module = 'TELEPHONE'")->order('sort'); $this->view->tags = $db->fetchAll($select); // show page number $selectTotalPage = $db->select(); $selectTotalPage->from('communicate_plan', 'total_consumers')->where('id = ?', $this->view->plan_id); $this->view->totalPage = $db->fetchOne($selectTotalPage); $selectCurrentPage = $db->select(); $selectCurrentPage->from('telephone_log', 'count(*)')->where('plan_id = ?', $this->view->plan_id)->where('id <= ?', $this->view->telephoneLog_id); $this->view->currentPage = $db->fetchOne($selectCurrentPage); // show call back page number $selectTotalCallbackPage = $db->select(); $selectTotalCallbackPage->from('telephone_log', 'count(*)')->where('plan_id = ?', $this->view->plan_id)->where('busy = 1'); $this->view->totalCallbackPage = $db->fetchOne($selectTotalCallbackPage); if (isset($messageArray) && isset($messageArray[0][0]) && ($messageArray[0][0] == 'nextcallbackView' || $messageArray[0][0] == 'precallbackView' || $messageArray[0][0] == 'firstcallbackView' || $messageArray[0][0] == 'finishcallbackView')) { if ($messageArray[0][0] == 'finishcallbackView') { $this->view->currentCallbackPage = 0; } else { $selectCurrentCallbackPage = $db->select(); $selectCurrentCallbackPage->from('telephone_log', 'count(*)')->where('plan_id = ?', $this->view->plan_id)->where('id <= ?', $this->view->telephoneLog_id)->where('busy = 1'); $this->view->currentCallbackPage = $db->fetchOne($selectCurrentCallbackPage); $this->view->callbackPageTitle = 'Call Back '; } } else { $this->view->currentCallbackPage = 0; } // show old telephone log $selectOldTelephoneLog = $db->select(); $selectOldTelephoneLog->from('telephone_log', '*')->where('consumer_id = ?', $consumer_id)->where("state != 'NEW'")->where('plan_id != ?', $this->view->plan_id); $this->view->oldTelephoneLogs = $db->fetchAll($selectOldTelephoneLog); $this->view->oldTelephoneLogTagArray = array(); foreach ($this->view->oldTelephoneLogs as $oldTelephoneLog) { $selectOldTelephoneLogTag = $db->select(); $selectOldTelephoneLogTag->from('tags', 'name')->join('telephone_log_tag', 'tags.id = telephone_log_tag.tag_id', null)->where('telephone_log_tag.telephone_log_id = ?', $oldTelephoneLog['id']); $this->view->oldTelephoneLogTagArray[$oldTelephoneLog['id']] = $db->fetchAll($selectOldTelephoneLogTag); } }