public function signup() { if (!OW::getRequest()->isAjax()) { exit(json_encode(array('result' => false))); } $lang = OW::getLanguage(); $form = new OCSAFFILIATES_CLASS_SignupForm('signup'); if (!$form->isValid($_POST)) { exit(json_encode(array('result' => 'false', 'error' => $lang->text('ocsaffiliates', 'fill_required_fields')))); } $service = OCSAFFILIATES_BOL_Service::getInstance(); $values = $form->getValues(); $affiliate = $service->findAffiliateByEmail($values['email']); if ($affiliate) { exit(json_encode(array('res' => false, 'error' => $lang->text('ocsaffiliates', 'email_exists')))); } $aff = new OCSAFFILIATES_BOL_Affiliate(); $aff->email = trim($values['email']); $aff->name = trim($values['name']); $aff->password = BOL_UserService::getInstance()->hashPassword($values['password']); $aff->paymentDetails = trim($values['payment']); $aff->registerStamp = time(); $aff->activityStamp = time(); $aff->joinIp = ip2long($service->getRemoteAddr()); $aff->emailVerified = 0; $aff->status = OW::getConfig()->getValue('ocsaffiliates', 'signup_status'); // check association if (OW::getUser()->isAuthenticated()) { $userId = OW::getUser()->getId(); $assocAff = $service->findAffiliateByAssocUser($userId); if (!$assocAff) { $aff->userId = $userId; } } else { $user = BOL_UserService::getInstance()->findByEmail($aff->email); if ($user) { $assocAff = $service->findAffiliateByAssocUser($user->id); if (!$assocAff) { $aff->userId = $user->d; } } } $id = $service->registerAffiliate($aff); if ($id) { $service->addVerificationRequest($aff->email); $service->loginAffiliateById($id); OW::getFeedback()->info($lang->text('ocsaffiliates', 'signup_successful')); exit(json_encode(array('result' => true))); } }
public function index() { $lang = OW::getLanguage(); $service = OCSAFFILIATES_BOL_Service::getInstance(); $online = $service->isAuthenticated(); $this->assign('online', $online); if ($online) { $affiliateId = $service->getAffiliateId(); $affiliate = $service->findAffiliateById($affiliateId); if (!$affiliate) { $service->logoutAffiliate(); $this->redirect(); } $this->assign('affiliate', $affiliate); $this->setPageHeading($lang->text('ocsaffiliates', 'affiliate_area')); $menu = $this->getMenu('dashboard'); $this->addComponent('menu', $menu); if (!$affiliate->emailVerified) { $form = new OCSAFFILIATES_CLASS_VerificationForm('verify'); $this->addForm($form); } else { $this->addComponent('stats', new OCSAFFILIATES_CMP_AffiliateStats($affiliateId)); $dayStart = strtotime("midnight"); $endOfDay = strtotime("tomorrow", $dayStart) - 1; $dayEnd = $endOfDay + date('Z'); $start = time(); if (!empty($_GET['range']) && in_array($_GET['range'], array('month', '2months'))) { switch ($_GET['range']) { case 'month': $start = strtotime("-1 month", $dayEnd); break; case '2months': $start = strtotime("-2 months", $dayEnd); } } else { $_GET['range'] = 'week'; $start = strtotime("-1 week", $dayEnd); } $this->assign('range', $_GET['range']); $end = $dayEnd; $stat = $service->getAffiliateEarningForPeriod($affiliateId, $start, $end); $sumData = ''; $max = $service->getAffiliateEarningMax($stat); foreach ($stat as $ts => $data) { $sumData .= '[' . $ts * 1000 . ', ' . $data['sum'] . ', 0, ' . 24 * 60 * 60 * 1000 . '], '; } $code = 'var datasets = { "sum": { lines: { show: true, lineWidth: 2, fill: true }, points: { show: true, radius: 2 }, shadowSize: 1, data: [' . $sumData . '], color: "rgba(153, 204, 255, 1)" } }; var data = []; data.push(datasets["sum"]); var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; var opt = { yaxis: { min: 0, max: ' . $max . ', tickColor: "#cfcfcf", position: "left" }, xaxis: { mode: "time", tickColor: "#cfcfcf", minTickSize: [1, "day"], timeformat: "%d %b", monthNames: monthNames }, grid: { hoverable: true, clickable: true, borderWidth: 1, borderColor: "#afafaf" }, points: { show: true }, legend: { position: "nw" } }; var options = $.extend(true, {}, opt, { hooks: { processRawData: function(a, b, c, d) { b.datapoints.format = [ { x: true, number: true, required: true }, { y: true, number: true, required: true }, { y: true, number: true, required: false, defaultValue: 0 }, { x: false, number: true, required: false } ]; }}} ); $.plot($("#stats_plot"), data, options); var previousPoint = null; $("#stats_plot").bind("plothover", function (event, pos, item) { $("#x").text(pos.x.toFixed(3)); $("#y").text(pos.y.toFixed(3)); if ( item ) { if ( previousPoint != item.datapoint ) { previousPoint = item.datapoint; $("#tooltip").remove(); var x = item.datapoint[0].toFixed(0), y = item.datapoint[1]; var objDate = new Date(item.datapoint[0]); showTooltip(item.pageX, item.pageY, monthNames[objDate.getMonth()] + " " + objDate.getDate() + " - " + "$" + y); } } else { $("#tooltip").remove(); previousPoint = null; } }); function showTooltip(x, y, contents) { $(\'<div id="tooltip">\' + contents + \'</div>\').css( { position: \'absolute\', display: \'none\', top: y - 35, color: \'#fff\', left: x + 5, padding: \'1px 3px\', \'background-color\': \'#007196\', \'font-weight\': \'bold\', \'border-radius\': \'3px\', \'font-size\': \'11px\', opacity: 0.90 }).appendTo("body").fadeIn(200); }; $("#stats-date-range").change(function(){ document.location.href = ' . json_encode(OW::getRouter()->urlForRoute('ocsaffiliates.home')) . ' + "/?range=" + $(this).val(); }); '; $jsUrl = OW::getPluginManager()->getPlugin('ocsaffiliates')->getStaticJsUrl(); OW::getDocument()->addScript($jsUrl . 'jquery.flot.min.js'); OW::getDocument()->addScript($jsUrl . 'jquery.flot.time.min.js'); OW::getDocument()->addOnloadScript($code); } $service->updateAffiliateActivity($affiliateId); // TODO: remove this code when a sale event is available $service->processUntrackedSales(); } else { $this->setPageHeading($lang->text('ocsaffiliates', 'earn_with_us')); $form = new OCSAFFILIATES_CLASS_SignupForm('signup'); if (OW::getUser()->isAuthenticated()) { $email = OW::getUser()->getEmail(); $affiliate = $service->findAffiliateByEmail($email); if (!$affiliate) { $form->getElement('email')->setValue($email); } } $this->addForm($form); $form = new OCSAFFILIATES_CLASS_SigninForm('affiliate-signin'); $this->addForm($form); $script = '$("#btn-forgot-password").click(function(){ document.forgotPasswordFloatBox = OW.ajaxFloatBox( "OCSAFFILIATES_CMP_ForgotPassword", { }, { width: 400, title: ' . json_encode($lang->text('ocsaffiliates', 'forgot_password')) . ' } ); }); '; $agreement = OW::getConfig()->getValue('ocsaffiliates', 'terms_agreement'); $this->assign('agreement', $agreement); if ($agreement) { $content = '<div>' . $lang->text('ocsaffiliates', 'terms_text') . '</div>'; $script .= '$("#affiliate-terms-link").click(function(){ fb = new OW_FloatBox({ $title: ' . json_encode($lang->text('ocsaffiliates', 'terms_of_use')) . ', $contents: $(' . json_encode($content) . '), width: 520 }); }); '; } OW::getDocument()->addOnloadScript($script); } }