function descriptionAction() { // $this->_helper->layout->disableLayout(); $db = Zend_Registry::get('db'); $campaign_id = $this->_request->getParam('id'); $currentTime = date("Y-m-d H:i:s"); $campaignModel = new Campaign(); $campaign = $campaignModel->fetchRow('id =' . $campaign_id); $campaignInvitation = new CampaignInvitation(); $invitation = $campaignInvitation->fetchRow("campaign_id = {$campaign_id} and campaign_invitation.consumer_id = " . $this->_currentUser->id); if ($campaign->public == 1 && !count($invitation)) { $campaignInvitation = new CampaignInvitation(); $row = $campaignInvitation->createRow(); $row->consumer_id = $this->_currentUser->id; $row->campaign_id = $campaign_id; $row->state = 'NEW'; $row->create_date = $currentTime; $row->save(); } if ($campaign->public == 0 && !count($invitation)) { $this->_helper->redirector('index', 'home'); } // $campaignInvitation = new CampaignInvitation(); $invitation = $campaignInvitation->fetchRow("campaign_id = {$campaign_id} and campaign_invitation.consumer_id = " . $this->_currentUser->id); $this->view->state = $invitation->state; //participate $select = $db->select(); $select->from('consumer', 'consumer.*'); $select->join('campaign_invitation', 'consumer.id = campaign_invitation.consumer_id and campaign_invitation.campaign_id =' . $campaign_id, 'campaign_id'); $select->join('campaign_participation', 'campaign_invitation.id = campaign_participation.campaign_invitation_id', 'accept_date'); $this->view->co = $db->fetchAll($select); $this->view->campaign_id = $campaign_id; //var_dump($this->view->activeMissions);die; }
function changeConsumerRank($uid) { //consumer information if (!isset($this->consumer)) { $this->consumer = new Consumer(); } $this->consumerData = $this->consumer->fetchRow('id = ' . $uid); //total points $this->rewardPointTransactionRecord = new RewardPointTransactionRecord(); $rewardData = $this->rewardPointTransactionRecord->fetchAll('consumer_id=' . $uid . ' and transaction_id !=4'); $rewardDataArray = $rewardData->toArray(); $total = 0; if (count($rewardDataArray)) { foreach ($rewardDataArray as $val) { $total += $val['point_amount']; } } //participated campaigns $campaign = new CampaignInvitation(); $campaignData = $campaign->fetchAll('state = "ACCEPTED" and consumer_id =' . $uid); $campaginNum = count($campaignData); //rank information $rank = $this->fetchRow('campaign_number<=' . $campaginNum . ' and point_total<=' . $total, 'point_total desc'); if (count($rank)) { if ($this->consumerData->rank == $rank->id) { return; } else { $this->consumerData->rank = $rank->id; $this->consumerData->save(); // add notification $notificationModel = new Notification(); $notificationModel->createRecord("RANK_UPGRADE", $uid); $row = $this->rewardPointTransactionRecord->createRow(); $row->consumer_id = $uid; $row->date = date("Y-m-d H:i:s"); $row->transaction_id = 7; $row->point_amount = $rank->point_bonus; $row->save(); $this->changeConsumerRank($uid); } } else { return; } }
function registerAction() { $this->view->title = "Register New Account"; $this->view->messages = $this->_flashMessenger->getMessages(); $this->_helper->layout->disableLayout(); $lang = $this->_request->getParam('lang'); if (isset($lang)) { $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; $this->_helper->redirector->gotoSimple('register', 'register', null, array('a' => $this->_request->getParam('a'), 'i' => $this->_request->getParam('i'))); } $db = Zend_Registry::get('db'); $currentTime = date("Y-m-d H:i:s"); $loginform = new LoginForm(); $this->view->form = $loginform; $form = new RegisterForm(); $this->view->registerForm = $form; $signupAuthCodeModel = new SignupAuthCode(); $auth_code = $this->_request->getParam('a'); if ($auth_code) { $form->auth_code->setValue($auth_code); $code = $signupAuthCodeModel->fetchRow("use_date is null and auth_code = '" . $auth_code . "'"); } // auto-fill code and email address if (isset($code) && $code->id) { $this->view->codeId = $code->id; $select1 = $db->select(); $select1->from("invitation_email", "to"); $select1->where("invitation_email.signup_auth_code_id = ?", $code->id); $toEmail = $db->fetchOne($select1); $form->registerEmail->setValue($toEmail); $code->view_date = $currentTime; $code->save(); } //public link $invite_code = $this->_request->getParam('i'); if ($invite_code) { $code2 = $signupAuthCodeModel->fetchRow("public_signup_link = true and auth_code = '" . $invite_code . "'"); $publicLinkValid = false; if (isset($code2)) { $select2 = $db->select(); $select2->from('signup_auth_code', 'count(*)')->where('use_date>date_sub(now(),interval 1 day)')->where('sender =' . $code2->sender)->where('source = "PUBLIC_LINK"')->where('receiver is not null'); $registered = $db->fetchOne($select2); if (intval($registered) < 100) { $publicLinkValid = true; } } } if (isset($code2)) { if ($publicLinkValid) { $codePattern = '1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZ'; $generatedCode = ''; for ($codeCount = 0; $codeCount < 12; $codeCount++) { $generatedCode = $generatedCode . $codePattern[mt_rand(0, 35)]; } $signupAuthCode = $signupAuthCodeModel->createRow(); $signupAuthCode->auth_code = $generatedCode; $signupAuthCode->create_date = $currentTime; $signupAuthCode->sender = $code2->sender; $signupAuthCode->source = 'PUBLIC_LINK'; $signupAuthCode->auto_invitation = $code2->auto_invitation; $signupAuthCode->save(); $form->auth_code->setValue($generatedCode); } else { $this->_flashMessenger->addMessage($this->view->translate('Sorry_This_register_link_has_been_overused')); $this->_helper->redirector('register', 'register'); } } if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $db = Zend_Registry::get('db'); if ($form->getValue('registerPassword') == $form->getValue('repeat')) { // verify auth code $codeModel = new SignupAuthCode(); $code = $codeModel->fetchRow("auth_code='" . $form->getValue('auth_code') . "' and use_date is null"); if ($code) { //check pest if ($code->sender != null) { $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow("id = " . $code->sender); if ($consumer != null && $consumer->pest == '1') { return; } } //check duplicated email $result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE email = :temp", array('temp' => $form->getValue('registerEmail'))); //check duplicated phone $phone_result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE login_phone = :temp", array('temp' => $form->getValue('loginPhone'))); if ($result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('registerEmail') . $this->view->translate('Register_email_is_invalid'); } else { if ($phone_result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('loginPhone') . $this->view->translate('Register_phone_is_invalid'); } else { $currentTime = date("Y-m-d H:i:s"); // save new consumer $consumerModel = new Consumer(); $row = $consumerModel->createRow(); $row->name = $form->getValue('name'); $row->email = $form->getValue('registerEmail'); $row->login_phone = $form->getValue('loginPhone'); $row->password = md5($form->getValue('registerPassword')); $row->save(); //expire the auth_code $code->receiver = $row->id; $code->use_date = $currentTime; $code->save(); //add points for code sender // if (!empty($code->sender)&& $code->sender!=""){ // $pointRecordModel = new RewardPointTransactionRecord(); // $point = $pointRecordModel->createRow(); // $point->consumer_id = $code->sender; // $point->transaction_id = 2; // $point->date = $currentTime; // $point->point_amount = 5; // $point->save(); // } // send auto intivitaion if (!empty($code->auto_invitation) && $code->auto_invitation != 0) { $campaignInvitationModel = new CampaignInvitation(); $ci = $campaignInvitationModel->createRow(); $ci->consumer_id = $row->id; $ci->campaign_id = $code->auto_invitation; $ci->create_date = $currentTime; $ci->state = "NEW"; $ci->save(); } // Login Automatically $authAdapter = new Zend_Auth_Adapter_DbTable($db); $authAdapter->setTableName('consumer'); $authAdapter->setIdentityColumn('email'); $authAdapter->setCredentialColumn('password'); $authAdapter->setIdentity($form->getValue('registerEmail')); $authAdapter->setCredential(md5($form->getValue('registerPassword'))); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = $row; $this->_flashMessenger->addMessage('Welcome!'); $this->_helper->redirector('index', 'home'); } } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_authcode_is_invalid'); } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_password_is_invalid'); } } else { $form->populate($formData); } } }
function registerAction() { $this->view->title = "Register New Account"; $this->view->messages = $this->_flashMessenger->getMessages(); $this->_helper->layout->disableLayout(); $lang = $this->_request->getParam('lang'); if (isset($lang)) { $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; $this->_helper->redirector->gotoSimple('register', 'register', null, array('a' => $this->_request->getParam('a'), 'i' => $this->_request->getParam('i'))); } $db = Zend_Registry::get('db'); $currentTime = date("Y-m-d H:i:s"); $loginform = new LoginForm(); $this->view->form = $loginform; $form = new RegisterForm(); $form->setAttrib('id', 'registerForm'); $this->view->registerForm = $form; $signupAuthCodeModel = new SignupAuthCode(); $auth_code = $this->_request->getParam('a'); if ($auth_code) { $form->auth_code->setValue($auth_code); $code = $signupAuthCodeModel->fetchRow("use_date is null and auth_code = '" . $auth_code . "'"); } // auto-fill code and email address if (isset($code) && $code->id) { $this->view->codeId = $code->id; $select1 = $db->select(); $select1->from("invitation_email", "to"); $select1->where("invitation_email.signup_auth_code_id = ?", $code->id); $toEmail = $db->fetchOne($select1); $form->registerEmail->setValue($toEmail); $code->view_date = $currentTime; $code->save(); } //public link $invite_code = $this->_request->getParam('i'); if ($invite_code) { $code2 = $signupAuthCodeModel->fetchRow("public_signup_link = true and auth_code = '" . $invite_code . "'"); $publicLinkValid = false; if (isset($code2)) { $select2 = $db->select(); $select2->from('signup_auth_code', 'count(*)')->where('use_date>date_sub(now(),interval 1 day)')->where('sender =' . $code2->sender)->where('source = "PUBLIC_LINK"')->where('receiver is not null'); $registered = $db->fetchOne($select2); if (intval($registered) < 100) { $publicLinkValid = true; } } } if (isset($code2)) { if ($publicLinkValid) { $codePattern = '1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZ'; $generatedCode = ''; for ($codeCount = 0; $codeCount < 12; $codeCount++) { $generatedCode = $generatedCode . $codePattern[mt_rand(0, 35)]; } $signupAuthCode = $signupAuthCodeModel->createRow(); $signupAuthCode->auth_code = $generatedCode; $signupAuthCode->create_date = $currentTime; $signupAuthCode->sender = $code2->sender; $signupAuthCode->source = 'PUBLIC_LINK'; $signupAuthCode->auto_invitation = $code2->auto_invitation; $signupAuthCode->save(); $form->auth_code->setValue($generatedCode); } else { $this->_flashMessenger->addMessage($this->view->translate('Sorry_This_register_link_has_been_overused')); $this->_helper->redirector('register', 'register'); } } if ($this->_request->isPost()) { $this->view->registered = 0; $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $db = Zend_Registry::get('db'); if ($form->getValue('registerPassword') == $form->getValue('repeat')) { //2011-04-01 ham register modification if (trim($form->getValue('auth_code')) == '') { //check duplicated email $result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE email = :temp", array('temp' => $form->getValue('registerEmail'))); //check duplicated phone $phone_result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE login_phone = :temp", array('temp' => $form->getValue('loginPhone'))); //var_dump($result);die; if ($result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('registerEmail') . $this->view->translate('Register_email_is_invalid'); } else { if ($phone_result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('loginPhone') . $this->view->translate('Register_phone_is_invalid'); } else { $currentTime = date("Y-m-d H:i:s"); $email = $form->getValue('registerEmail'); //generate enable account link $codePattern = '1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZ'; $active_code = ''; for ($codeCount = 0; $codeCount < 12; $codeCount++) { $active_code = $active_code . $codePattern[mt_rand(0, 35)]; } $activeLink = $this->view->home . '/public/register/activate/p/' . $active_code; //save link into DB $tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 1, date("Y")); $expire_date = date("Y-m-d H:i:s", $tomorrow); $temporaryLinkModel = new TemporaryLink(); $temporaryLink = array("link" => $activeLink, "email" => $email, "expire_date" => $expire_date); $temporaryLink_id = $temporaryLinkModel->insert($temporaryLink); //send mail $emailSubject = $this->view->translate('ENABLE_ACCOUNT_subject'); $emailBody = $this->view->translate('ENABLE_ACCOUNT_body'); $stringChange = array("?ENABLEACCOUNTLINK?" => $activeLink); $emailBody = strtr($emailBody, $stringChange); $config = Zend_Registry::get('config'); $smtpSender = new Zend_Mail_Transport_Smtp($config->smtp->invitation->mail->server, array('username' => $config->smtp->invitation->mail->username, 'password' => $config->smtp->invitation->mail->password, 'auth' => $config->smtp->invitation->mail->auth, 'ssl' => $config->smtp->invitation->mail->ssl, 'port' => $config->smtp->invitation->mail->port)); // $smtpSender = new Zend_Mail_Transport_Smtp( // 'smtp.163.com',array( // 'username'=>'*****@*****.**', // 'password'=>'19990402', // 'auth'=>'login')); Zend_Mail::setDefaultTransport($smtpSender); $mail = new Zend_Mail('utf-8'); $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->setFrom($config->smtp->forgetpassword->mail->username, $this->view->translate('Wildfire')); // $mail->setFrom('*****@*****.**','yun_simon'); $mail->addTo($email); $mail->send(); // save new consumer $consumerModel = new Consumer(); $row = $consumerModel->createRow(); $row->name = $form->getValue('name'); $row->email = $form->getValue('registerEmail'); $row->login_phone = $form->getValue('loginPhone'); $row->password = md5($form->getValue('registerPassword')); $row->state = "ACTIVE"; $row->save(); $this->view->registered = 1; } } //2011-04-01 ham register modification } else { // verify auth code $codeModel = new SignupAuthCode(); $code = $codeModel->fetchRow("auth_code='" . $form->getValue('auth_code') . "' and use_date is null"); if ($code != NULL) { //check pest if ($code->sender != null) { $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow("id = " . $code->sender); if ($consumer != null && $consumer->pest == '1') { return; } } //check duplicated email $result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE email = :temp", array('temp' => $form->getValue('registerEmail'))); //check duplicated phone $phone_result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE login_phone = :temp", array('temp' => $form->getValue('loginPhone'))); if ($result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('registerEmail') . $this->view->translate('Register_email_is_invalid'); } else { if ($phone_result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('loginPhone') . $this->view->translate('Register_phone_is_invalid'); } else { $currentTime = date("Y-m-d H:i:s"); //2011-04-02 ham.bao add the logic of activating the account $email = $form->getValue('registerEmail'); //generate enable account link $codePattern = '1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZ'; $active_code = ''; for ($codeCount = 0; $codeCount < 12; $codeCount++) { $active_code = $active_code . $codePattern[mt_rand(0, 35)]; } $activeLink = $this->view->home . '/public/register/activate/p/' . $active_code; //save link into DB $tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 1, date("Y")); $expire_date = date("Y-m-d H:i:s", $tomorrow); $temporaryLinkModel = new TemporaryLink(); $temporaryLink = array("link" => $activeLink, "email" => $email, "expire_date" => $expire_date); $temporaryLink_id = $temporaryLinkModel->insert($temporaryLink); //send mail //2011-04-02 ham.bao add the logic of activating the account // save new consumer $consumerModel = new Consumer(); $row = $consumerModel->createRow(); $row->name = $form->getValue('name'); $row->email = $form->getValue('registerEmail'); $row->login_phone = $form->getValue('loginPhone'); $row->password = md5($form->getValue('registerPassword')); $row->state = "ACTIVE"; $row->save(); //expire the auth_code $code->receiver = $row->id; $code->use_date = $currentTime; $code->save(); //add points for code sender // if (!empty($code->sender)&& $code->sender!=""){ // $pointRecordModel = new RewardPointTransactionRecord(); // $point = $pointRecordModel->createRow(); // $point->consumer_id = $code->sender; // $point->transaction_id = 2; // $point->date = $currentTime; // $point->point_amount = 5; // $point->save(); // } // send auto intivitaion if (!empty($code->auto_invitation) && $code->auto_invitation != 0) { $campaignInvitationModel = new CampaignInvitation(); $ci = $campaignInvitationModel->createRow(); $ci->consumer_id = $row->id; $ci->campaign_id = $code->auto_invitation; $ci->create_date = $currentTime; $ci->state = "NEW"; $ci->save(); } $this->view->registered = 1; // Login Automatically $authAdapter = new Zend_Auth_Adapter_DbTable($db); $authAdapter->setTableName('consumer'); $authAdapter->setIdentityColumn('email'); $authAdapter->setCredentialColumn('password'); $authAdapter->setIdentity($form->getValue('registerEmail')); $authAdapter->setCredential(md5($form->getValue('registerPassword'))); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = $row; $this->_flashMessenger->addMessage('Welcome!'); $this->_helper->redirector('index', 'home'); } } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_authcode_is_invalid'); } } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_repeat_password_is_error'); } } else { $form->populate($formData); } } }
function rejectinvitationAction() { if ($this->autoAccountBinding() == false) { return; } $consumer = $this->_currentUser; $campaign_id = $this->_request->getParam('campaign_id', 0); if ($campaign_id == 0) { Zend_Debug::dump('it should redirect to an error page'); return; } $db = Zend_Registry::get('db'); $select_invitations = $db->select(); $select_invitations->from('campaign_invitation', '*'); $select_invitations->where('campaign_id=?', $campaign_id); $select_invitations->where('consumer_id=?', $consumer['id']); $select_invitations->where('state=?', 'NEW'); $invitations = $db->fetchRow($select_invitations); if (!isset($invitations['id'])) { Zend_Debug::dump('The consumer have no right to reject this invitation'); return; } $invitation_model = new CampaignInvitation(); $invitation_model_row = $invitation_model->fetchRow('id=' . $invitations['id']); $invitation_model_row->state = 'REJECTED'; $invitation_model_row->save(); }
function admincompletemissionAction() { $consumer = $this->_request->getParam('consumer'); $campaign = $this->_request->getParam('campaign'); $currentTime = date("Y-m-d H:i:s"); $campaignInvitation = new CampaignInvitation(); $campaignInvitation->update(array('state' => 'COMPLETED'), 'consumer_id =' . $consumer . ' and campaign_id =' . $campaign); $campainInvitationRow = $campaignInvitation->fetchRow('consumer_id =' . $consumer . ' and campaign_id =' . $campaign); $campaignParticipation = new CampaignParticipation(); $row = $campaignParticipation->createRow(); $row->campaign_invitation_id = $campainInvitationRow->id; $row->accept_date = $currentTime; $row->state = 'COMPLETED'; $row->save(); $this->_helper->layout->disableLayout(); die('结束'); }
function precampaignfinishedAction() { $this->view->activeTab = 'Campaign'; $this->view->title = $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("You_are_in"); //precampaignsurvey的css使用的是layout_survey $this->_helper->layout->setLayout("layout_survey"); $id = (int) $this->_request->getParam('survey'); $campaignModel = new Campaign(); $this->view->campaign = $campaignModel->fetchRow("pre_campaign_survey=" . $id . " or " . "pre_campaign_survey_en=" . $id); $db = Zend_Registry::get('db'); if ($this->view->campaign != null) { $campaignId = $this->view->campaign->id; } $consumer = $this->_currentUser; //TOCHECK //$select_extra_info = $db->select (); //$select_extra_info->from ( "consumer",array ('consumer.*', 'consumer_extra_info.gender as gender','consumer_extra_info.education as education','consumer_extra_info.income as income' )); //$select_extra_info->joinLeft ( "consumer_extra_info","consumer.id = consumer_extra_info.consumer_id",null); //$select_extra_info->where("consumer.id = ".$this->_currentUser->id ); //$consumer2 = $db->fetchRow ( $select_extra_info ); //Zend_Debug::dump($consumer2);die; if ($this->view->campaign != null && $campaignId != null && $campaignId > 0) { // check if precampaign poll is finished // $select1 = $db->select(); // $select1->from('campaign', 'pre_campaign_survey'); // $select1->where('campaign.id = ?',$campaignId); // $previewCamSurvey = $db->fetchOne($select1); // $indicate2Connect = new Indicate2_Connect(); // $ids = array($previewCamSurvey); // $wsResult = $indicate2Connect->getAnswerSetCount($consumer->email,$ids); // // if ($wsResult==0){ // $this->_redirect('campaign/precampaign/survey/'.$previewCamSurvey); // }else{ $campaignInvitationModel = new CampaignInvitation(); $campaignInvitation = $campaignInvitationModel->fetchRow("campaign_id=" . $campaignId . " and consumer_id=" . $consumer->id); if ($campaignInvitation == null) { $this->_redirect('http://community.wildfire.asia/public/home'); } $id = $campaignInvitation->id; //Zend_Debug::dump($campaignInvitation); $campaignInvitation->state = "ACCEPTED"; $campaignInvitation->save(); //2011-05-19 ham.bao add the badge // $consumerBadgeModel = new ConsumerBadge(); // $notificationModel = new Notification(); // $consumerBadgeData = $consumerBadgeModel->fetchRow('badge='.$this->view->campaign->badge .' and consumer='.$consumer->id); // if(!count($consumerBadgeData)){ // $row = $consumerBadgeModel->createRow(); // $row->consumer = $consumer->id; // $row->badge = $this->view->campaign->badge; // $row->create_date = date("Y-m-d H:i:s"); // $row->save(); // // add notification // $notificationModel->createRecord("CONSUMER_BADGE",$consumer->id); // // } //2011-05-19 ham.bao add the badge $result = $db->fetchOne("SELECT COUNT(*) FROM campaign_participation WHERE campaign_invitation_id=:t1", array('t1' => $id)); if ($result == 0) { //2011-02-22 ham.bao add the logic to calculate the number of participation $campaignModel->update(array('participation' => $this->view->campaign->participation + 1), 'id = ' . $this->view->campaign->id); if ($this->view->campaign->participation + 1 >= $this->view->campaign->total) { $campaignInvitationModel->update(array('state' => 'EXPIRED'), ' state = "NEW" and campaign_id =' . $this->view->campaign->id); $signauthcodeModel = new SignupAuthCode(); $signauthcodeModel->update(array('auto_invitation' => 0), 'auto_invitation =' . $this->view->campaign->id); } //create participation $campaignParticipationModel = new CampaignParticipation(); $currentTime = date("Y-m-d H:i:s"); $row = $campaignParticipationModel->createRow(); $row->campaign_invitation_id = $id; $row->accept_date = $currentTime; $row->state = 'NEW'; $row->save(); //send "welcome to campaign" mail //set the content of mail $emailSubject = $this->view->translate('Welcome_to_Spark_Campaign_Email_subject_campaign_' . $campaignId); $emailBody = $this->view->translate('Welcome_to_Spark_Campaign_Email_body_campaign_' . $campaignId); $stringChange = array('?USERNAME?' => $this->_currentUser['name']); $emailBody = strtr($emailBody, $stringChange); //send... $config = Zend_Registry::get('config'); $smtpSender = new Zend_Mail_Transport_Smtp($config->smtp->welcome->mail->server, array('username' => $config->smtp->welcome->mail->username, 'password' => $config->smtp->welcome->mail->password, 'auth' => $config->smtp->welcome->mail->auth, 'ssl' => $config->smtp->welcome->mail->ssl, 'port' => $config->smtp->welcome->mail->port)); Zend_Mail::setDefaultTransport($smtpSender); $mail = new Zend_Mail('utf-8'); $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->setFrom($config->smtp->welcome->mail->username, $this->view->translate('Wildfire')); $mail->addTo($this->_currentUser['email']); $mail->send(); } } //edit ConsumerContactForm(); $form = new ConsumerContactForm(array('relative' => $this->view->campaign->relative)); $consumer = $this->_currentUser; $order = new Zend_Db_Expr(' id '); $consumerFriend = new ConsumerFriend(); $friends = $consumerFriend->fetchAll('consumer= ' . $consumer->id . ' and campaign=' . $this->view->campaign->id, $order); $this->view->friendsNum = count($friends); //consumer_extra_info /*$consumer_extra_info = new ConsumerExtraInfo(); //TOCHECK $consumerextra = $consumer_extra_info->fetchAll("consumer_id= ".$consumer->id);*/ $select_consumer_extra_info = $db->select(); $select_consumer_extra_info->from('consumer_extra_info', '*')->where('consumer_extra_info.consumer_id = ?', $consumer->id); $consumerextra = $db->fetchAll($select_consumer_extra_info); if ($this->_request->getPost()) { $formData = $this->_request->getPost(); $form->populate($formData); $this->view->city = $formData["city"]; $this->view->province = $formData["province"]; $this->view->encity = $formData["city"]; } else { $form->populate($consumer->toArray()); $form->birthdate->setValue($consumerextra[0]['birthdate']); $form->gender->setValue($consumerextra[0]['gender']); $form->education->setValue($consumerextra[0]['education']); $form->income->setValue($consumerextra[0]['income']); $form->telephone->setValue($consumer->company_phone); // zh city if ($consumer["city"] != NULL && $consumer["province"] != NULL) { $this->view->city = $consumer["city"]; $this->view->province = $consumer["province"]; } // en city if ($consumer["city"] != NULL && $consumer["province"] == NULL) { $this->view->encity = $consumer["city"]; } if (count($friends)) { $i = 1; foreach ($friends as $friend) { $name = 'friend_name_' . $i; $email = 'friend_email_' . $i; $phone = 'friend_phone_' . $i; $address = 'friend_address_' . $i; $message = 'friend_message_' . $i; $form->{$name}->setValue($friend->name); $form->{$email}->setValue($friend->email); $form->{$phone}->setValue($friend->phone); $form->{$address}->setValue($friend->address); $form->{$message}->setValue($friend->message); $i++; } } } //var_dump($form);die; $langNamespace = new Zend_Session_Namespace('Lang'); $this->view->language = $langNamespace->lang; $this->view->form = $form; $this->view->friendsLimit = $this->view->campaign->relative; //Zend_Debug::dump($this->_request->getPost ()); //Zend_Debug::dump($this->view->friendsLimit); }
function adminreportAction() { $this->_helper->layout->setLayout("layout_admin"); $sms_id = (int) $this->_request->getParam('sms_id'); $smsSql = "select b.* from spark_sms as a, spark_sms as b where a.id=" . $sms_id . " and b.consumer_id=a.consumer_id and b.id-a.id>-5 and b.id-a.id<5 order by b.id"; $db = Zend_Registry::get('db'); $rs = $db->fetchAll($smsSql); $sms = ''; $consumer_id = 0; $smsIds = array(); foreach ($rs as $row) { array_push($smsIds, $row['id']); $sms .= $row['text']; $consumer_id = $row['consumer_id']; } //update sms state $ids = implode(",", $smsIds); //Zend_Debug::dump($ids); $updateSql = $db->prepare("update spark_sms set state='Reported' where id in (" . $ids . ")"); $updateSql->execute(); $campaign_id = (int) $this->_request->getParam('cam_id'); //whether participate in the campaign $campaigninvitationModel = new CampaignInvitation(); $campaigninvitation = $campaigninvitationModel->fetchRow('campaign_id = ' . $campaign_id . ' and consumer_id' . ' =' . $consumer_id); if ($campaigninvitation == null) { $this->_helper->redirector('index', 'home'); } //get lang $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow("id=" . $consumer_id); //get i2_survey_id $campaignModel = new Campaign(); $campaign = $campaignModel->fetchRow("id=" . $campaign_id); $langNamespace = new Zend_Session_Namespace('Lang'); $lang = $langNamespace->lang; if ($consumer->language_pref == 'en') { $surveyId = $campaign->i2_survey_id_en; } else { $surveyId = $campaign->i2_survey_id; } $this->view->campaing_name = $campaign->name; $indicate2Connect = new Indicate2_Connect(); $accesscode = $indicate2Connect->createParticipation($consumer->email, $surveyId); //save list in session $reportNamespace = new Zend_Session_Namespace('AgentReports'); $reportNamespace->{$accesscode} = $consumer_id; $source = $accesscode . "_source"; $reportNamespace->{$source} = "sms"; $config = Zend_Registry::get('config'); $this->view->filloutPage = $config->indicate2->home . "/c/" . $accesscode . "/theme/wildfire"; $this->view->id = $consumer->id; $this->view->name = $consumer->name; $this->view->sms = $sms; $this->view->includeCrystalCss = true; }
function adminconverttoreportAction() { $this->_helper->layout->disableLayout(); $idValue = explode('&', $this->_request->getParam('id')); $id = $idValue[0]; $emailModel = new IncomingEmail(); $emailData = $emailModel->fetchRow('id=' . $id); $consumerModel = new Consumer(); $consumerData = $consumerModel->fetchRow('email like "%' . $emailData->email . '%"'); if ($consumerData != NULL) { $this->view->consumer = true; } else { $this->view->consumer = false; } $campaignModel = new Campaign(); $campaignData = $campaignModel->fetchRow('create_date < "' . date('Y-m-d H:i:s') . '" and "' . date('Y-m-d H:i:s') . '"<expire_date'); if ($this->view->consumer) { $campaigninvitationModel = new CampaignInvitation(); $campaigninvitationData = $campaigninvitationModel->fetchRow('campaign_id = ' . $campaignData->id . ' and consumer_id=' . $consumerData->id); if ($campaigninvitationData) { $this->view->invitation = true; } else { $this->view->invitation = false; } } if ($this->view->consumer && $this->view->invitation) { $emailSession = new Zend_Session_Namespace('IncomingEmail'); $emailSession->email = $emailData->email; $langNamespace = new Zend_Session_Namespace('Lang'); $lang = $langNamespace->lang; if ($lang == 'en') { $surveyId = $campaignData->i2_survey_id_en; } else { $surveyId = $campaignData->i2_survey_id; } $this->view->file = "./surveys/" . $surveyId . ".phtml"; } $this->_helper->layout->setLayout("layout_questionnaire"); }
function profileAction() { $this->_helper->layout->setLayout("layout_admin"); $uid = $this->_request->getParam('uid'); $campainId = $this->_request->getParam('campaign'); if ($campainId != '') { $campaignInvitationModel = new CampaignInvitation(); $data = $campaignInvitationModel->fetchAll('consumer_id = ' . $uid . ' and campaign_id =' . $campainId); if (count($data) == 0) { $row = $campaignInvitationModel->createRow(); $row->campaign_id = $campainId; $row->consumer_id = $uid; $row->create_date = date("Y-m-d H:i:s"); $row->state = "NEW"; $row->save(); } $this->_helper->redirector('profile', 'consumer', '', array('uid' => $uid)); } $search = $this->_request->getParam('search'); $this->view->search = $search; $campaignInfo = array(); $reportsInfo = array(); $userModel = new Consumer(); if ($this->_request->getParam('resetpassword')) { $userModel->update(array('password' => md5('111111')), 'id =' . $uid); $this->_helper->redirector('profile', 'consumer', null, array('uid' => $uid)); } $profile = $userModel->fetchRow('id =' . $uid); $userExtraInfo = new ConsumerExtraInfo(); $extra_profile = $userExtraInfo->fetchRow(' consumer_id = ' . $uid); $this->view->profile = $profile; $this->view->extra_profile = $extra_profile; // var_dump($extra_profile);die; $db = Zend_Registry::get('db'); $select = $db->select(); $select->from("campaign", array('campaign.*', 'campaign_participation.state', 'campaign_invitation.state as cstate', 'campaign_invitation.id as ciid')); $select->joinLeft("campaign_invitation", "campaign.id=campaign_invitation.campaign_id and campaign_invitation.consumer_id = " . $uid, null); $select->joinLeft("campaign_participation", "campaign_invitation.id=campaign_participation.campaign_invitation_id", "campaign_participation.accept_date"); //$select->where ( "campaign_invitation.state = 'ACCEPTED'" ); //$select->where ( " campaign_invitation.consumer_id = ?", $uid ); $select->order('campaign_participation.accept_date desc'); $campaignsAll = $db->fetchAll($select); $this->view->campaigns = $campaignsAll; //survey $db = Zend_Registry::get('db'); $select_survey = $db->select(); $select_survey->from('profile_survey', array('name', 'english_name', 'state')); $select_survey->join('poll_participation', 'poll_participation.poll_id = profile_survey.id', 'poll_participation.date'); $select_survey->join('reward_point_transaction_record', 'reward_point_transaction_record.date = poll_participation.date and reward_point_transaction_record.consumer_id = poll_participation.consumer_id', 'point_amount'); $select_survey->where('reward_point_transaction_record.transaction_id =3'); $select_survey->where('poll_participation.consumer_id = ?', $uid); $select_survey->order('poll_participation.date desc'); $surveysAll = $db->fetchAll($select_survey); $this->view->surveysall = $surveysAll; // point detail /*$db = Zend_Registry::get('db'); $select_pointdetail = $db->select(); $select_pointdetail->from(); $select_pointdetail->join(); $select_pointdetail->join(); $select_pointdetail->where(); $select_pointdetail->where(); $select_pointdetail->order(); $surveysAll = $db->fetchAll($select_pointdetail);*/ //var_dump($campaignsAll);die; $selectTotal = $db->select(); $selectTotal->from("report", array('count(id) as num', 'campaign_id')); $selectTotal->where("consumer_id =" . $uid); $selectTotal->group('campaign_id'); $totalData = $db->fetchAll($selectTotal); if (count($totalData)) { foreach ($totalData as $val) { $reportsInfo[$val['campaign_id']] = $val['num']; } } $this->view->totalreports = $reportsInfo; // 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' => $uid)); if (empty($this->view->totalPoints)) { $this->view->totalPoints = 0; } //redeem points $this->view->redeemPoints = $db->fetchOne("SELECT sum(point_amount) FROM reward_point_transaction_record WHERE consumer_id = :temp", array('temp' => $uid)); if (empty($this->view->redeemPoints)) { $this->view->redeemPoints = 0; } //usable points $today = date("Y-m-d", time()); $this->view->usablePoints = $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' => $uid, 'temp2' => date("Y-m-d", strtotime("{$today} -30 day")))); if (empty($this->view->usablePoints)) { $this->view->usablePoints = 0; } $redeemSelect = $db->select(); $redeemSelect->from('product_order', array('product_order.amount as amount', 'product_order.create_date', 'product_order.state as pstate', 'product_order.id as pid', 'product.name', 'reward_point_transaction_record.point_amount')); $redeemSelect->join('product', 'product_order.product_id=product.id'); $redeemSelect->join('reward_point_transaction_record', 'product_order.reward_point_transaction_record_id=reward_point_transaction_record.id'); $redeemSelect->where('product_order.consumer_id=?', $uid); $this->view->redeem = $db->fetchAll($redeemSelect); $translate = new Zend_Translate('array', array("Value is required and can't be empty" => $this->view->translate('validation_null'))); $form = new ConsumerSearchForm(); $form->setTranslator($translate); if ($this->_request->getParam('search') != null) { $search = $this->_request->getParam('search'); $form->search->setValue($search); } $this->view->form = $form; }
function rejectAction() { $compaign_id = (int) $this->_request->getParam('id'); $campaignInvitationModel = new CampaignInvitation(); $row = $campaignInvitationModel->fetchRow('campaign_id = ' . $compaign_id . ' and consumer_id = ' . $this->_currentUser->id); $row->state = 'REJECTED'; $row->save(); $this->_helper->redirector('index', 'campaigninvitation'); // Zend_Debug::dump($compaign_id); }
function adminreportAction() { $request = $this->getRequest(); if ($request->isPost()) { $formData = $this->_request->getPost(); $consumer_id = $formData['consumer_id']; $campaign_id = $formData['campaign_id']; $comment = $formData['phone_comments']; $source = $formData['source']; //whether participate in the campaign $campaigninvitationModel = new CampaignInvitation(); $campaigninvitation = $campaigninvitationModel->fetchRow('campaign_id = ' . $campaign_id . ' and consumer_id' . ' =' . $consumer_id); if ($campaigninvitation == null) { //$this->_helper->redirector('index','home'); } //get i2_survey_id $campaignModel = new Campaign(); $campaign = $campaignModel->fetchRow("id=" . $campaign_id); $langNamespace = new Zend_Session_Namespace('Lang'); $lang = $langNamespace->lang; if ($lang == 'en') { $surveyId = $campaign->i2_survey_id_en; } else { $surveyId = $campaign->i2_survey_id; } $this->view->campaing_name = $campaign->name; $this->view->id = $campaign_id; $indicate2Connect = new Indicate2_Connect(); $accesscode = $indicate2Connect->createParticipation('', $surveyId); $config = Zend_Registry::get('config'); $this->view->filloutPage = $config->indicate2->home . "/c/" . $accesscode . "/theme/wildfire"; //save list in session $reportNamespace = new Zend_Session_Namespace('AgentReports'); $source_key = $accesscode . '_source'; $reportNamespace->{$source_key} = $source; $reportNamespace->{$accesscode} = $consumer_id; $this->view->includeCrystalCss = true; } }