From 4ad8ee2472bc63ff29acd7e97bb5617dea96feb7 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 18 Oct 2012 14:32:56 -0400 Subject: [PATCH 001/285] - removing a line for saas --- airtime_mvc/application/controllers/ScheduleController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index a8b5b557c..d893b590f 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -797,7 +797,7 @@ class ScheduleController extends Zend_Controller_Action if (!$validateStartTime) { $this->view->when->getElement('add_show_start_time')->setOptions(array('disabled' => true)); } - $this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true)); + //$this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true)); $this->view->addNewShow = false; $this->view->action = "edit-show"; $this->view->form = $this->view->render('schedule/add-show-form.phtml'); From d23ba12aaab3c86d8b09182a25c872918c25514d Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 19 Oct 2012 15:42:09 -0400 Subject: [PATCH 002/285] CC-4608: Chat Box is gone on sourcefabric.airtime.pro -fixed --- airtime_mvc/application/Bootstrap.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index c4c53ffa5..6b698c3d6 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -75,6 +75,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendScript("var baseUrl='$baseUrl/'"); //scripts for now playing bar + $view->headScript()->appendFile($baseUrl.'/js/airtime/airtime_bootstrap.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/helperfunctions.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/dashboard.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/versiontooltip.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); @@ -89,9 +90,13 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap } else { $userType = ""; } - $view->headScript()->appendScript("var userType = '$userType';"); - + if (strpos($_SERVER['REQUEST_URI'], $baseUrl.'/Dashboard/stream-player') === false + && strpos($_SERVER['REQUEST_URI'], $baseUrl.'/audiopreview/audio-preview') === false) { + $client_id = Application_Model_Preference::GetClientId(); + $view->headScript()->appendScript("var livechat_client_id = '$client_id';"); + $view->headScript()->appendFile($baseUrl . '/js/airtime/common/livechat.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + } if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1) { $view->headScript()->appendFile($baseUrl.'/js/libs/google-analytics.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); From b4264f83e8282c555196801fd13f092c8d119c84 Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 19 Oct 2012 15:45:14 -0400 Subject: [PATCH 003/285] CC-4608: Chat Box is gone on sourcefabric.airtime.pro --- airtime_mvc/application/Bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 6b698c3d6..392161212 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -90,6 +90,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap } else { $userType = ""; } + + $view->headScript()->appendScript("var userType = '$userType';"); if (strpos($_SERVER['REQUEST_URI'], $baseUrl.'/Dashboard/stream-player') === false && strpos($_SERVER['REQUEST_URI'], $baseUrl.'/audiopreview/audio-preview') === false) { From 70ed5548b9ddc5563caf1873e2d7f7a0a93f4e75 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 23 Oct 2012 16:50:25 -0400 Subject: [PATCH 004/285] -chat box was appearing in playlist-preview window --- airtime_mvc/application/Bootstrap.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 392161212..ce3096d0f 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -94,7 +94,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendScript("var userType = '$userType';"); if (strpos($_SERVER['REQUEST_URI'], $baseUrl.'/Dashboard/stream-player') === false - && strpos($_SERVER['REQUEST_URI'], $baseUrl.'/audiopreview/audio-preview') === false) { + && strpos($_SERVER['REQUEST_URI'], $baseUrl.'/audiopreview/audio-preview') === false + && strpos($_SERVER['REQUEST_URI'], $baseUrl.'/audiopreview/playlist-preview') === false) { $client_id = Application_Model_Preference::GetClientId(); $view->headScript()->appendScript("var livechat_client_id = '$client_id';"); $view->headScript()->appendFile($baseUrl . '/js/airtime/common/livechat.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); From a4d91a5d48e279d33a354f57d47d388f719e7677 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 23 Oct 2012 17:44:06 -0400 Subject: [PATCH 005/285] CC-4620: Now Playing page loading is very slow because 1M records in cc_schedule table -small fix --- airtime_mvc/application/models/Schedule.php | 45 +++++++++++-------- .../application/models/ShowBuilder.php | 3 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 233128433..b668f13e5 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -263,6 +263,15 @@ SQL; global $CC_CONFIG; $con = Propel::getConnection(); + $p_start_str = $p_start->format("Y-m-d H:i:s"); + $p_end_str = $p_end->format("Y-m-d H:i:s"); + + + //We need to search 24 hours before and after the show times so that that we + //capture all of the show's contents. + $p_track_start= $p_start->sub(new DateInterval("PT24H"))->format("Y-m-d H:i:s"); + $p_track_end = $p_end->add(new DateInterval("PT24H"))->format("Y-m-d H:i:s"); + $templateSql = <<= '{$p_start}' - AND sched.starts < '{$p_end}') - OR (sched.ends > '{$p_start}' - AND sched.ends <= '{$p_end}') - OR (sched.starts <= '{$p_start}' - AND sched.ends >= '{$p_end}')) + AND ((sched.starts >= '{$p_track_start}' + AND sched.starts < '{$p_track_end}') + OR (sched.ends > '{$p_track_start}' + AND sched.ends <= '{$p_track_end}') + OR (sched.starts <= '{$p_track_start}' + AND sched.ends >= '{$p_track_end}')) ) SQL; @@ -315,12 +324,12 @@ SQL; $streamJoin = <<= '{$p_start}' - AND sched.starts < '{$p_end}') - OR (sched.ends > '{$p_start}' - AND sched.ends <= '{$p_end}') - OR (sched.starts <= '{$p_start}' - AND sched.ends >= '{$p_end}')) + AND ((sched.starts >= '{$p_track_start}' + AND sched.starts < '{$p_track_end}') + OR (sched.ends > '{$p_track_start}' + AND sched.ends <= '{$p_track_end}') + OR (sched.starts <= '{$p_track_start}' + AND sched.ends >= '{$p_track_end}')) ) LEFT JOIN cc_subjs AS sub ON (ws.creator_id = sub.id) SQL; @@ -358,12 +367,12 @@ SELECT showt.name AS show_name, JOIN cc_show AS showt ON (showt.id = si.show_id) WHERE si.modified_instance = FALSE $showPredicate - AND ((si.starts >= '{$p_start}' - AND si.starts < '{$p_end}') - OR (si.ends > '{$p_start}' - AND si.ends <= '{$p_end}') - OR (si.starts <= '{$p_start}' - AND si.ends >= '{$p_end}')) + AND ((si.starts >= '{$p_start_str}' + AND si.starts < '{$p_end_str}') + OR (si.ends > '{$p_start_str}' + AND si.ends <= '{$p_end_str}') + OR (si.starts <= '{$p_start_str}' + AND si.ends >= '{$p_end_str}')) ORDER BY si_starts, sched_starts; SQL; diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php index 90a67a1d6..8436c3011 100644 --- a/airtime_mvc/application/models/ShowBuilder.php +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -423,8 +423,7 @@ class Application_Model_ShowBuilder } $scheduled_items = Application_Model_Schedule::GetScheduleDetailItems( - $this->startDT->format("Y-m-d H:i:s"), $this->endDT->format( - "Y-m-d H:i:s"), $shows); + $this->startDT, $this->endDT, $shows); for ($i = 0, $rows = count($scheduled_items); $i < $rows; $i++) { From b8d6132b52eb65f305b36f113fc8f45ba4dfbf1f Mon Sep 17 00:00:00 2001 From: James Date: Tue, 23 Oct 2012 18:47:15 -0400 Subject: [PATCH 006/285] - saas patch #1 --- .../application/controllers/ApiController.php | 16 +++++++ .../controllers/PreferenceController.php | 1 - .../forms/SoundcloudPreferences.php | 10 ----- airtime_mvc/application/models/RabbitMq.php | 42 +++++++++++++++++++ airtime_mvc/application/models/User.php | 12 +++++- .../scripts/form/preferences_soundcloud.phtml | 13 ------ 6 files changed, 69 insertions(+), 25 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 1a1876ce9..5d07d250a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -686,6 +686,22 @@ class ApiController extends Zend_Controller_Action Logging::info("Registered Component: ".$component."@".$remoteAddr); Application_Model_ServiceRegister::Register($component, $remoteAddr); + + //send ip, subdomain + if (Application_Model_Preference::GetPlanLevel() != 'disabled'){ + if ($component == "pypo"){ + $split = explode('.', $_SERVER['SERVER_NAME']); + if (count($split) > 0){ + $subDomain = $split[0]; + + $md = array(); + $md["sub_domain"] = $subDomain; + $md["pypo_ip"] = $remoteAddr; + + Application_Model_RabbitMq::SendMessageToHaproxyConfigDaemon($md); + } + } + } } public function updateLiquidsoapStatusAction() diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 5c375deab..c1ffda4ad 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -53,7 +53,6 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetMailServerRequiresAuth($values["preferences_email_server"]["msRequiresAuth"]); } - Application_Model_Preference::SetAutoUploadRecordedShowToSoundcloud($values["preferences_soundcloud"]["UseSoundCloud"]); Application_Model_Preference::SetUploadToSoundcloudOption($values["preferences_soundcloud"]["UploadToSoundcloudOption"]); Application_Model_Preference::SetSoundCloudDownloadbleOption($values["preferences_soundcloud"]["SoundCloudDownloadbleOption"]); Application_Model_Preference::SetSoundCloudUser($values["preferences_soundcloud"]["SoundCloudUser"]); diff --git a/airtime_mvc/application/forms/SoundcloudPreferences.php b/airtime_mvc/application/forms/SoundcloudPreferences.php index d3840cbbf..848368697 100644 --- a/airtime_mvc/application/forms/SoundcloudPreferences.php +++ b/airtime_mvc/application/forms/SoundcloudPreferences.php @@ -11,16 +11,6 @@ class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm array('ViewScript', array('viewScript' => 'form/preferences_soundcloud.phtml')) )); - //enable soundcloud uploads - $this->addElement('checkbox', 'UseSoundCloud', array( - 'label' => 'Automatically Upload Recorded Shows', - 'required' => false, - 'value' => Application_Model_Preference::GetAutoUploadRecordedShowToSoundcloud(), - 'decorators' => array( - 'ViewHelper' - ) - )); - //enable soundcloud uploads option $this->addElement('checkbox', 'UploadToSoundcloudOption', array( 'label' => 'Enable SoundCloud Upload', diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index d92975413..7fea88348 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -71,4 +71,46 @@ class Application_Model_RabbitMq self::sendMessage($exchange, $data); } + + public static function SendMessageToHaproxyConfigDaemon($md){ + $config = parse_ini_file("/etc/airtime-saas/rabbitmq.ini", true); + $conn = new AMQPConnection($config["rabbitmq"]["host"], + $config["rabbitmq"]["port"], + $config["rabbitmq"]["user"], + $config["rabbitmq"]["password"], + $config["rabbitmq"]["vhost"]); + + $exchange = $config["rabbitmq"]["queue"]; + $queue = $config["rabbitmq"]["queue"]; + + $ch = $conn->channel(); + + + /* + name: $queue + passive: false + durable: true // the queue will survive server restarts + exclusive: false // the queue can be accessed in other channels + auto_delete: false //the queue won't be deleted once the channel is closed. + */ + $ch->queue_declare($queue, false, true, false, false); + + /* + name: $exchange + type: direct + passive: false + durable: true // the exchange will survive server restarts + auto_delete: false //the exchange won't be deleted once the channel is closed. + */ + + $ch->exchange_declare($exchange, 'direct', false, true, false); + $ch->queue_bind($queue, $exchange); + + $data = json_encode($md).PHP_EOL; + $msg = new AMQPMessage($data, array('content_type' => 'application/json')); + + $ch->basic_publish($msg, $exchange); + $ch->close(); + $conn->close(); + } } diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 63b82820a..48a4c3e2f 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -329,14 +329,24 @@ class Application_Model_User $res = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables); // mark record which is for the current user - foreach ($res['aaData'] as &$record) { + foreach($res['aaData'] as $key => &$record){ if ($record['login'] == $username) { $record['delete'] = "self"; } else { $record['delete'] = ""; } + + if($record['login'] == 'sourcefabric_admin'){ + //arrays in PHP are basically associative arrays that can be iterated in order. + //Deleting an earlier element does not change the keys of elements that come after it. --MK + unset($res['aaData'][$key]); + $res['iTotalDisplayRecords']--; + $res['iTotalRecords']--; + } } + $res['aaData'] = array_values($res['aaData']); + return $res; } diff --git a/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml b/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml index 20bcc92c9..8a007c10d 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml @@ -13,19 +13,6 @@ -
- - element->getElement('UseSoundCloud')->hasErrors()) : ?> -
    - element->getElement('UseSoundCloud')->getMessages() as $error): ?> -
  • - -
- -
- isSaas ){?> -
- -
-
- element->getElement('master_harbor_input_port') ?> - element->getElement('master_harbor_input_port')->hasErrors()) : ?> -
    - element->getElement('master_harbor_input_port')->getMessages() as $error): ?> -
  • - -
- -
-
- -
-
- element->getElement('master_harbor_input_mount_point') ?> - element->getElement('master_harbor_input_mount_point')->hasErrors()) : ?> -
    - element->getElement('master_harbor_input_mount_point')->getMessages() as $error): ?> -
  • - -
- -
-
element->getElement('master_dj_connection_url')->setValue($this->master_dj_connection_url) ?> - isSaas && !$this->isDemo){?> - Override   - -
-
- isSaas ){?> -
- -
-
- element->getElement('dj_harbor_input_port') ?> - element->getElement('dj_harbor_input_port')->hasErrors()) : ?> -
    - element->getElement('dj_harbor_input_port')->getMessages() as $error): ?> -
  • - -
- -
-
- -
-
- element->getElement('dj_harbor_input_mount_point') ?> - element->getElement('dj_harbor_input_mount_point')->hasErrors()) : ?> -
    - element->getElement('dj_harbor_input_mount_point')->getMessages() as $error): ?> -
  • - -
- -
-
element->getElement('live_dj_connection_url')->setValue($this->live_dj_connection_url) ?> - isSaas && !$this->isDemo ){?> - Override   - -
- diff --git a/airtime_mvc/application/views/scripts/form/support-setting.phtml b/airtime_mvc/application/views/scripts/form/support-setting.phtml index f35a6eab1..012cbb6a7 100644 --- a/airtime_mvc/application/views/scripts/form/support-setting.phtml +++ b/airtime_mvc/application/views/scripts/form/support-setting.phtml @@ -1,45 +1,5 @@
-isSaas ){?> -
-
-
- Help Airtime improve by letting Sourcefabric know how you are using it. This information - will be collected regularly in order to enhance your user experience.
- Click the "Send support feedback" box and we'll make sure the features you use are - constantly improving. -
- - element->getElement('SupportFeedback')->hasErrors()) : ?> -
    - element->getElement('SupportFeedback')->getMessages() as $error): ?> -
  • - -
- -
-
-
Click the box below to promote your station on - Sourcefabric.org. -
- - element->getElement('Publicise')->hasErrors()) : ?> -
    - element->getElement('Publicise')->getMessages() as $error): ?> -
  • - -
- -
-
-
(In order to promote your station, "Send support feedback" must be enabled).

- -
;"> +
;">
-isSaas ){?> -
-
- Show me what I am sending -
- element->getElement('SendInfo') ?> -
-
-
- -
-
- element->getView()->privacyChecked){?> - - element->getElement('Privacy')->hasErrors()) : ?> -
    - element->getElement('Privacy')->getMessages() as $error): ?> -
  • - -
- - - Sourcefabric Privacy Policy - -
- diff --git a/airtime_mvc/application/views/scripts/menu.phtml b/airtime_mvc/application/views/scripts/menu.phtml index 0e6eb8dc1..215fbbcf1 100644 --- a/airtime_mvc/application/views/scripts/menu.phtml +++ b/airtime_mvc/application/views/scripts/menu.phtml @@ -1,9 +1,3 @@ - + diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index 2c0ef024a..dae344b70 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -92,10 +92,36 @@ function setCollapsibleWidgetJsCode() { $('#widgetCode-label').hide("fast"); $('#widgetCode-element').hide("fast"); } - }); } +function createWidgetHelpDescription() { + $('#thirdPartyApiInfo').qtip({ + content: { + text: "Enabling this feature will allow Airtime to " + + "provide schedule data to external widgets that can be embedded " + + "in your website. Enable this feature to reveal the embeddable " + + "code." + }, + hide: { + delay: 500, + fixed: true + }, + style: { + border: { + width: 0, + radius: 4 + }, + classes: "ui-tooltip-dark ui-tooltip-rounded" + }, + position: { + my: "left bottom", + at: "right center" + }, + }); + +} + $(document).ready(function() { $('.collapsible-header').live('click',function() { @@ -111,4 +137,5 @@ $(document).ready(function() { setConfigureMailServerListener(); setEnableSystemEmailsListener(); setCollapsibleWidgetJsCode(); + createWidgetHelpDescription(); }); From bb8f5e107c93c5f120148a3ef8393283d32c45a0 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 7 Nov 2012 17:19:47 -0500 Subject: [PATCH 015/285] CC-4661: Listener Statistics -ability to gather stats without admin password --- python_apps/pypo/listenerstat.py | 26 ++++++++++++-------------- python_apps/pypo/pypocli.py | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/python_apps/pypo/listenerstat.py b/python_apps/pypo/listenerstat.py index 431f05e98..306015a58 100644 --- a/python_apps/pypo/listenerstat.py +++ b/python_apps/pypo/listenerstat.py @@ -10,8 +10,9 @@ import time from api_clients import api_client class ListenerStat(Thread): - def __init__(self, logger=None): + def __init__(self, config, logger=None): Thread.__init__(self) + self.config = config self.api_client = api_client.AirtimeApiClient() if logger is None: self.logger = logging.getLogger() @@ -31,20 +32,18 @@ class ListenerStat(Thread): def get_icecast_xml(self, ip): - encoded = base64.b64encode("%(admin_user)s:%(admin_password)s" % ip) + #encoded = base64.b64encode("%(admin_user)s:%(admin_password)s" % ip) - header = {"Authorization":"Basic %s" % encoded} + #header = {"Authorization":"Basic %s" % encoded} self.logger.debug(ip) - url = 'http://%(host)s:%(port)s/admin/stats.xml' % ip + url = 'http://%(host)s:%(port)s/stats.xsl' % ip self.logger.debug(url) - req = urllib2.Request( - #assuming that the icecast stats path is /admin/stats.xml - #need to fix this - url=url, - headers=header) + req = urllib2.Request(url=url) + #headers=header) f = urllib2.urlopen(req) document = f.read() + return document @@ -78,11 +77,10 @@ class ListenerStat(Thread): #streams are the same server, we will still initiate 3 separate #connections for k, v in stream_parameters.items(): - v["admin_user"] = "admin" - v["admin_password"] = "hackme" + #v["admin_user"] = "admin" + #v["admin_password"] = "hackme" if v["enable"] == 'true': stats.append(self.get_icecast_stats(v)) - #stats.append(get_shoutcast_stats(ip)) return stats @@ -123,5 +121,5 @@ if __name__ == "__main__": # add ch to logger #logger.addHandler(ch) - ls = ListenerStat(logger) - ls.run() + #ls = ListenerStat(logger=logger) + #ls.run() diff --git a/python_apps/pypo/pypocli.py b/python_apps/pypo/pypocli.py index 1b51a13f8..ac511c8e5 100644 --- a/python_apps/pypo/pypocli.py +++ b/python_apps/pypo/pypocli.py @@ -210,7 +210,7 @@ if __name__ == '__main__': recorder.daemon = True recorder.start() - stat = ListenerStat() + stat = ListenerStat(config) stat.daemon = True stat.start() From a0a9fc71f171928c22dcc4b22552d7e7a555cc94 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 12 Nov 2012 17:44:26 -0500 Subject: [PATCH 016/285] disable unlimited attempts for pushing stats data --- python_apps/api_clients/api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index ca1f37cd8..22c28e7c4 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -764,7 +764,7 @@ class AirtimeApiClient(object): json_data = json.dumps(data) encoded_data = urllib.urlencode({'data': json_data}) request = urllib2.Request(url, encoded_data) - print self.get_response_from_server(request) + print self.get_response_from_server(request, attempts = 1) except Exception, e: self.logger.error("Exception: %s", e) From 0f2d5bc844e1ac69b95ab8e801fe4df179da0d87 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 12 Nov 2012 17:45:20 -0500 Subject: [PATCH 017/285] files should not be independent events --- airtime_mvc/application/models/Schedule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index aceeb3849..f98547059 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -687,7 +687,7 @@ SQL; 'end' => $end, 'show_name' => $item["show_name"], 'replay_gain' => is_null($item["replay_gain"]) ? "0": $item["replay_gain"], - 'independent_event' => true + 'independent_event' => false ); self::appendScheduleItem($data, $start, $schedule_item); } From d8165cbf44f70b8983e3b80af1e17755a56577e0 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 13 Nov 2012 16:32:36 -0500 Subject: [PATCH 018/285] - haproxy support subdomain name with '.' --- .../application/controllers/ApiController.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 928d5adb0..5ad5bfbad 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -693,13 +693,21 @@ class ApiController extends Zend_Controller_Action if (Application_Model_Preference::GetPlanLevel() != 'disabled'){ if ($component == "pypo"){ $split = explode('.', $_SERVER['SERVER_NAME']); - if (count($split) > 0){ - $subDomain = $split[0]; - + $subdomain = array(); + foreach ($split as $value) { + if ($value == 'airtime') { + break; + } else { + $subdomain[] = $value; + } + } + if (count($subdomain) > 0){ + $subDomain = implode('.',$subdomain); + $md = array(); $md["sub_domain"] = $subDomain; $md["pypo_ip"] = $remoteAddr; - + Application_Model_RabbitMq::SendMessageToHaproxyConfigDaemon($md); } } From 858f03c9ad126a11c98da80296c5c350ce08b17b Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 29 Nov 2012 15:58:29 -0500 Subject: [PATCH 019/285] -remove rebroadcast code --- airtime_mvc/application/forms/AddShowWhen.php | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 5f8105657..3dbc63b86 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -250,35 +250,6 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $valid = false; $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); } - } elseif ($formData["add_show_rebroadcast"]) { - /* Check first show - * Continue if the first show does not overlap - */ - $overlapping = Application_Model_Schedule::checkOverlappingShows($show_start, $show_end, $update, $instanceId); - - if (!$overlapping) { - $durationToAdd = "PT".$hours."H".$minutes."M"; - for ($i = 1; $i <= 10; $i++) { - - if (empty($formData["add_show_rebroadcast_date_absolute_".$i])) break; - - $abs_rebroadcast_start = $formData["add_show_rebroadcast_date_absolute_".$i]." ". - $formData["add_show_rebroadcast_time_absolute_".$i]; - $rebroadcastShowStart = new DateTime($abs_rebroadcast_start); - $rebroadcastShowStart->setTimezone(new DateTimeZone('UTC')); - $rebroadcastShowEnd = clone $rebroadcastShowStart; - $rebroadcastShowEnd->add(new DateInterval($durationToAdd)); - $overlapping = Application_Model_Schedule::checkOverlappingShows($rebroadcastShowStart, $rebroadcastShowEnd, $update, $instanceId); - if ($overlapping) { - $valid = false; - $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); - break; - } - } - } else { - $valid = false; - $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); - } } else { $overlapping = Application_Model_Schedule::checkOverlappingShows($show_start, $show_end, $update, $instanceId); if ($overlapping) { From 3086bde17ebd8ad481abc624f5728f0a7783effa Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 4 Dec 2012 16:22:03 -0500 Subject: [PATCH 020/285] -cleanup parsing for form elements that weren't provided by the client in our SaaS implementation --- .../controllers/PreferenceController.php | 34 +++++++------------ .../application/forms/SupportSettings.php | 17 ---------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 7ab568144..6450626e5 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -70,30 +70,20 @@ class PreferenceController extends Zend_Controller_Action if ($request->isPost()) { $values = $request->getPost(); if ($form->isValid($values)) { - if ($values["Publicise"] != 1) { - Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); - Application_Model_Preference::SetPublicise($values["Publicise"]); - if (isset($values["Privacy"])) { - Application_Model_Preference::SetPrivacyPolicyCheck($values["Privacy"]); - } - } else { - Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); - Application_Model_Preference::SetPhone($values["Phone"]); - Application_Model_Preference::SetEmail($values["Email"]); - Application_Model_Preference::SetStationWebSite($values["StationWebSite"]); - Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); - Application_Model_Preference::SetPublicise($values["Publicise"]); + Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); + Application_Model_Preference::SetPhone($values["Phone"]); + Application_Model_Preference::SetEmail($values["Email"]); + Application_Model_Preference::SetStationWebSite($values["StationWebSite"]); - $form->Logo->receive(); - $imagePath = $form->Logo->getFileName(); + $form->Logo->receive(); + $imagePath = $form->Logo->getFileName(); - Application_Model_Preference::SetStationCountry($values["Country"]); - Application_Model_Preference::SetStationCity($values["City"]); - Application_Model_Preference::SetStationDescription($values["Description"]); - Application_Model_Preference::SetStationLogo($imagePath); - if (isset($values["Privacy"])) { - Application_Model_Preference::SetPrivacyPolicyCheck($values["Privacy"]); - } + Application_Model_Preference::SetStationCountry($values["Country"]); + Application_Model_Preference::SetStationCity($values["City"]); + Application_Model_Preference::SetStationDescription($values["Description"]); + Application_Model_Preference::SetStationLogo($imagePath); + if (isset($values["Privacy"])) { + Application_Model_Preference::SetPrivacyPolicyCheck($values["Privacy"]); } $this->view->statusMsg = "
Support setting updated.
"; } diff --git a/airtime_mvc/application/forms/SupportSettings.php b/airtime_mvc/application/forms/SupportSettings.php index aeda6d7ed..827b9013b 100644 --- a/airtime_mvc/application/forms/SupportSettings.php +++ b/airtime_mvc/application/forms/SupportSettings.php @@ -126,20 +126,6 @@ class Application_Form_SupportSettings extends Zend_Form } $this->addElement($checkboxPublicise); - // text area for sending detail - $this->addElement('textarea', 'SendInfo', array( - 'class' => 'sending_textarea', - 'required' => false, - 'filters' => array('StringTrim'), - 'readonly' => true, - 'cols' => 61, - 'rows' => 5, - 'value' => Application_Model_Preference::GetSystemInfo(false, true), - 'decorators' => array( - 'ViewHelper' - ) - )); - // checkbox for privacy policy $checkboxPrivacy = new Zend_Form_Element_Checkbox("Privacy"); $checkboxPrivacy->setLabel("By checking this box, I agree to Sourcefabric's privacy policy.") @@ -159,9 +145,6 @@ class Application_Form_SupportSettings extends Zend_Form public function isValid ($data) { $isValid = parent::isValid($data); - if ($data['Publicise'] != 1) { - $isValid = true; - } if (isset($data["Privacy"])) { $checkPrivacy = $this->getElement('Privacy'); if ($data["SupportFeedback"] == "1" && $data["Privacy"] != "1") { From b1985e2bdff4bb085b2db1478f108c5158fe5a8a Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 4 Dec 2012 17:42:28 -0500 Subject: [PATCH 021/285] SAAS-290: Hosted SaaS widgets + javascript code generation -fix code box not automatically expanding on page refresh --- airtime_mvc/public/js/airtime/preferences/preferences.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index dae344b70..8a4c619c6 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -82,8 +82,9 @@ function setMsAuthenticationFieldsReadonly(ele) { } function setCollapsibleWidgetJsCode() { - $('#thirdPartyApi-element input').click(function() { - if ($(this).first().attr("value") == '1') { + var x = function() { + var val = $('input:radio[name=thirdPartyApi]:checked').val(); + if (val == "1") { //show js textarea $('#widgetCode-label').show("fast"); $('#widgetCode-element').show("fast"); @@ -92,7 +93,9 @@ function setCollapsibleWidgetJsCode() { $('#widgetCode-label').hide("fast"); $('#widgetCode-element').hide("fast"); } - }); + } + x(); + $('#thirdPartyApi-element input').click(x); } function createWidgetHelpDescription() { From c57e19983c1cbfa37eaac5c6aa5af1e998c0978e Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 15 Jan 2013 14:06:02 -0500 Subject: [PATCH 022/285] -fix merge mistakes from devel --- .../application/views/scripts/form/preferences_general.phtml | 5 +++++ airtime_mvc/public/js/airtime/preferences/preferences.js | 1 + 2 files changed, 6 insertions(+) diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index 96d7fb607..3a75aed95 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -64,6 +64,11 @@ element->getElement('widgetCode')->hasErrors()) : ?>
    element->getElement('widgetCode')->getMessages() as $error): ?> +
  • + +
+ +
diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index 595881ca8..0c50762b0 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -121,6 +121,7 @@ function createWidgetHelpDescription() { at: "right center" }, }); +} function setSoundCloudCheckBoxListener() { var subCheckBox= $("#UseSoundCloud,#SoundCloudDownloadbleOption"); From e46ba0eb776ecbce3e9cff9fe5224d22462d5f60 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 15 Jan 2013 15:46:07 -0500 Subject: [PATCH 023/285] Changed version number in UpgradeCommon.php --- .../upgrades/airtime-2.3.0/common/UpgradeCommon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install_minimal/upgrades/airtime-2.3.0/common/UpgradeCommon.php b/install_minimal/upgrades/airtime-2.3.0/common/UpgradeCommon.php index 496a576a2..ee7c9fe09 100644 --- a/install_minimal/upgrades/airtime-2.3.0/common/UpgradeCommon.php +++ b/install_minimal/upgrades/airtime-2.3.0/common/UpgradeCommon.php @@ -11,8 +11,8 @@ class UpgradeCommon{ const CONF_PYPO_GRP = "pypo"; const CONF_WWW_DATA_GRP = "www-data"; - const CONF_BACKUP_SUFFIX = "220"; - const VERSION_NUMBER = "2.2.0"; + const CONF_BACKUP_SUFFIX = "230"; + const VERSION_NUMBER = "2.3.0"; public static function SetDefaultTimezone() { From 6fe4840e3277b34c4dcb9c6e08f408e3148b6314 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 15 Jan 2013 16:22:17 -0500 Subject: [PATCH 024/285] CC-4797: Generate localization locales on install -check if locale exists before writing it to /etc/locale.gen on Debian --- install_minimal/include/airtime-initialize.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install_minimal/include/airtime-initialize.sh b/install_minimal/include/airtime-initialize.sh index d07320c80..623daa9de 100755 --- a/install_minimal/include/airtime-initialize.sh +++ b/install_minimal/include/airtime-initialize.sh @@ -11,7 +11,10 @@ dist=`lsb_release -is` echo "Generating locales" for i in `ls /usr/share/airtime/locale | grep ".._.."`; do if [ "$dist" = "Debian" ]; then - echo "$i.UTF-8 UTF-8" >> /etc/locale.gen + grep -q "$i" /etc/locale.gen + if [ $? -ne 0 ]; then + echo "$i.UTF-8 UTF-8" >> /etc/locale.gen + fi else locale-gen "$i.utf8" fi From 4d3f5e1ba4a9233531e327423fb4a0e251d2be9b Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 15 Jan 2013 16:27:50 -0500 Subject: [PATCH 025/285] Reverting last commit --- install_minimal/include/airtime-initialize.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/install_minimal/include/airtime-initialize.sh b/install_minimal/include/airtime-initialize.sh index 623daa9de..d07320c80 100755 --- a/install_minimal/include/airtime-initialize.sh +++ b/install_minimal/include/airtime-initialize.sh @@ -11,10 +11,7 @@ dist=`lsb_release -is` echo "Generating locales" for i in `ls /usr/share/airtime/locale | grep ".._.."`; do if [ "$dist" = "Debian" ]; then - grep -q "$i" /etc/locale.gen - if [ $? -ne 0 ]; then - echo "$i.UTF-8 UTF-8" >> /etc/locale.gen - fi + echo "$i.UTF-8 UTF-8" >> /etc/locale.gen else locale-gen "$i.utf8" fi From 712df8b12d5efb0d3e15499f073a80e404f5a19b Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 16 Jan 2013 11:10:23 -0500 Subject: [PATCH 026/285] Removed extra style element --- .../application/views/scripts/form/preferences_general.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index 3a75aed95..880ba1d54 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -27,7 +27,7 @@ -
+
From bd3d12bd263a81568e5a78a0a3624c9e56c5b962 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 16 Jan 2013 12:34:20 -0500 Subject: [PATCH 027/285] CC-4849: 2.3.x-saas: Empty page for Support feedback -fixed --- .../application/views/scripts/form/support-setting.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/views/scripts/form/support-setting.phtml b/airtime_mvc/application/views/scripts/form/support-setting.phtml index aeadecfa1..6ec97da13 100644 --- a/airtime_mvc/application/views/scripts/form/support-setting.phtml +++ b/airtime_mvc/application/views/scripts/form/support-setting.phtml @@ -1,5 +1,5 @@
-
;"> +
;">
+ diff --git a/airtime_mvc/application/views/scripts/user/add-user.phtml b/airtime_mvc/application/views/scripts/user/add-user.phtml index a85744a46..b58607a89 100644 --- a/airtime_mvc/application/views/scripts/user/add-user.phtml +++ b/airtime_mvc/application/views/scripts/user/add-user.phtml @@ -26,6 +26,9 @@ +
successMessage ?>
diff --git a/airtime_mvc/public/js/airtime/user/user.js b/airtime_mvc/public/js/airtime/user/user.js index 3473e1acf..f3a414b66 100644 --- a/airtime_mvc/public/js/airtime/user/user.js +++ b/airtime_mvc/public/js/airtime/user/user.js @@ -4,6 +4,17 @@ function populateForm(entries){ $('.errors').remove(); $('.success').remove(); + if (entries.type === 'S') + { + $("#user_details").hide(); + $("#user_details_superadmin_message").show(); + $('#type').attr('disabled', '1'); + } else { + $("#user_details").show(); + $("#user_details_superadmin_message").hide(); + $('#type').removeAttr('disabled'); + } + $('#user_id').val(entries.id); $('#login').val(entries.login); $('#first_name').val(entries.first_name); @@ -23,12 +34,6 @@ function populateForm(entries){ $('#password').val(""); $('#passwordVerify').val(""); } - if (entries.login === 'admin') - { - $('#type').attr('disabled', '1'); - } else { - $('#type').removeAttr('disabled'); - } } function rowClickCallback(row_id){ @@ -66,6 +71,7 @@ function rowCallback( nRow, aData, iDisplayIndex ){ } else if ( aData['type'] == "S" ) { $('td:eq(3)', nRow).html( $.i18n._('Super Admin') ); + $('td:eq(4)', nRow).html(""); //Disable deleting the super admin } return nRow; From 01bf2883e5d59d298da846d54388a3163ce3eebf Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 20 Jun 2014 15:00:28 -0400 Subject: [PATCH 128/285] Save client info on upgrade --- .../controllers/BillingController.php | 34 +++++++++++++++---- .../views/scripts/billing/upgrade.phtml | 4 ++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 189aa28f6..91a06b80d 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -15,7 +15,6 @@ class BillingController extends Zend_Controller_Action { //$formData = $form->getValues(); $formData = $request->getPost(); if ($form->isValid($formData)) { - $credentials = self::getAPICredentials(); $postfields = array(); @@ -33,15 +32,36 @@ class BillingController extends Zend_Controller_Action { $postfields["paymentmethod"] = $formData["paymentmethod"]; $postfields["responsetype"] = "json"; - $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + $upgrade_query_string = ""; + foreach ($postfields AS $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; //update client info + $clientfields = array(); + $clientfields["username"] = $credentials["username"]; + $clientfields["password"] = md5($credentials["password"]); + $clientfields["action"] = "updateclient"; + //$clientfields["clientid"] = Application_Model_Preference::GetClientId(); + $clientfields["clientid"] = 1846; + $clientfields["responsetype"] = "json"; + unset($formData["newproductid"]); + unset($formData["newproductbillingcycle"]); + unset($formData["paymentmethod"]); + unset($formData["action"]); + $clientfields = array_merge($clientfields, $formData); + unset($clientfields["password2verify"]); + unset($clientfields["submit"]); + $client_query_string = ""; + foreach ($clientfields AS $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; - - //$result = $this->makeRequest($credentials["url"], $query_string); - //self::viewInvoice($result["invoiceid"]); - self::viewInvoice(5108); + $result = $this->makeRequest($credentials["url"], $client_query_string); + if ($result["result"] == "error") { + $this->view->errorMessage = "An error occurred and we could not upgrade your account. Please contact support for help"; + $this->view->form = $form; + } else { + //$result = $this->makeRequest($credentials["url"], $upgrade_query_string); + //self::viewInvoice($result["invoiceid"]); + self::viewInvoice(5108); + } } else { $this->view->form = $form; } diff --git a/airtime_mvc/application/views/scripts/billing/upgrade.phtml b/airtime_mvc/application/views/scripts/billing/upgrade.phtml index d22807b64..6d40d3b0d 100644 --- a/airtime_mvc/application/views/scripts/billing/upgrade.phtml +++ b/airtime_mvc/application/views/scripts/billing/upgrade.phtml @@ -1,5 +1,7 @@
-successMessage ?> +errorMessage)) {?> +
errorMessage ?>
+
Plan Level:
form ?>



From 1e1dc1dd03daabaa6a9dd6654a0eccab8e93df13 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 20 Jun 2014 16:31:26 -0400 Subject: [PATCH 129/285] Validation Refactoring --- .../controllers/BillingController.php | 117 ++++++++++-------- .../views/scripts/billing/client.phtml | 5 + 2 files changed, 71 insertions(+), 51 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 91a06b80d..50af88b03 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -55,7 +55,7 @@ class BillingController extends Zend_Controller_Action { $result = $this->makeRequest($credentials["url"], $client_query_string); if ($result["result"] == "error") { - $this->view->errorMessage = "An error occurred and we could not upgrade your account. Please contact support for help"; + $this->setErrorMessage(); $this->view->form = $form; } else { //$result = $this->makeRequest($credentials["url"], $upgrade_query_string); @@ -70,10 +70,27 @@ class BillingController extends Zend_Controller_Action { } } + private function setErrorMessage($msg=null) + { + if (!is_null($msg)) { + $this->view->errorMessage = $msg; + } else { + $this->view->errorMessage = "An error occurred and we could not update your account. Please contact support for help."; + } + } + + private function setSuccessMessage($msg=null) + { + if (!is_null($msg)) { + $this->view->successMessage = $msg; + } else { + $this->view->successMessage = "Your account has been updated."; + } + } + private static function getAPICredentials() { return array( - "access_key" => $_SERVER["WHMCS_ACCESS_KEY"], "username" => $_SERVER["WHMCS_USERNAME"], "password" => $_SERVER["WHMCS_PASSWORD"], "url" => "https://account.sourcefabric.com/includes/api.php?accesskey=".$_SERVER["WHMCS_ACCESS_KEY"], @@ -98,28 +115,37 @@ class BillingController extends Zend_Controller_Action { $form = new Application_Form_BillingClient(); if ($request->isPost()) { $formData = $request->getPost(); + if ($form->isValid($formData)) { - $accessKey = $_SERVER["WHMCS_ACCESS_KEY"]; - $username = $_SERVER["WHMCS_USERNAME"]; - $password = $_SERVER["WHMCS_PASSWORD"]; - $url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; - - $postfields = array(); - $postfields["username"] = $username; - $postfields["password"] = md5($password); - $postfields["action"] = "updateclient"; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["clientid"] = 1846; - $postfields = array_merge($postfields, $formData); - unset($postfields["password2verify"]); - unset($postfields["submit"]); - - $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; - - $result = $this->makeRequest($url, $query_string); - $form = new Application_Form_BillingClient(); - $this->view->form = $form; + $credentials = self::getAPICredentials(); + + $postfields = array(); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); + $postfields["action"] = "updateclient"; + //$postfields["clientid"] = Application_Model_Preference::GetClientId(); + $postfields["clientid"] = 18460000000; + $postfields["responsetype"] = "json"; + $postfields = array_merge($postfields, $formData); + unset($postfields["password2verify"]); + unset($postfields["submit"]); + + $query_string = ""; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + + $result = $this->makeRequest($credentials["url"], $query_string); + + if ($result["result"] == "error") { + $this->setErrorMessage(); + } else { + $form = new Application_Form_BillingClient(); + $this->setSuccessMessage(); + } + + $this->view->form = $form; + } else { + $this->view->form = $form; + } } else { $this->view->form = $form; } @@ -127,14 +153,11 @@ class BillingController extends Zend_Controller_Action { public function invoicesAction() { - $accessKey = $_SERVER["WHMCS_ACCESS_KEY"]; - $username = $_SERVER["WHMCS_USERNAME"]; - $password = $_SERVER["WHMCS_PASSWORD"]; - $url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; + $credentials = self::getAPICredentials(); $postfields = array(); - $postfields["username"] = $username; - $postfields["password"] = md5($password); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getinvoices"; $postfields["responsetype"] = "json"; $postfields["userid"] = 1846; @@ -143,7 +166,7 @@ class BillingController extends Zend_Controller_Action { $query_string = ""; foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; - $result = self::makeRequest($url, $query_string); + $result = self::makeRequest($credentials["url"], $query_string); $this->view->invoices = $result["invoices"]["invoice"]; } @@ -157,14 +180,11 @@ class BillingController extends Zend_Controller_Action { //TODO: this does not return a service id. why? private static function getClientInstanceId() { - $accessKey = $_SERVER["WHMCS_ACCESS_KEY"]; - $username = $_SERVER["WHMCS_USERNAME"]; - $password = $_SERVER["WHMCS_PASSWORD"]; - $url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; + $credentials = self::getAPICredentials(); $postfields = array(); - $postfields["username"] = $username; - $postfields["password"] = md5($password); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getclientsproducts"; $postfields["responsetype"] = "json"; $postfields["clientid"] = 1846; @@ -173,42 +193,37 @@ class BillingController extends Zend_Controller_Action { $query_string = ""; foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; - $result = self::makeRequest($url, $query_string); + $result = self::makeRequest($credentials["url"], $query_string); Logging::info($result); } public static function getProducts() { - $accessKey = $_SERVER["WHMCS_ACCESS_KEY"]; - $username = $_SERVER["WHMCS_USERNAME"]; - $password = $_SERVER["WHMCS_PASSWORD"]; - $url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; + $credentials = self::getAPICredentials(); $postfields = array(); - $postfields["username"] = $username; - $postfields["password"] = md5($password); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getproducts"; $postfields["responsetype"] = "json"; + //gid is the Airtime product group id on whmcs $postfields["gid"] = "15"; $query_string = ""; foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; - $result = self::makeRequest($url, $query_string); + $result = self::makeRequest($credentials["url"], $query_string); return $result["products"]["product"]; } public static function getClientDetails() { try { - $accessKey = $_SERVER["WHMCS_ACCESS_KEY"]; - $username = $_SERVER["WHMCS_USERNAME"]; - $password = $_SERVER["WHMCS_PASSWORD"]; - $url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; + $credentials = self::getAPICredentials(); $postfields = array(); - $postfields["username"] = $username; - $postfields["password"] = md5($password); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getclientsdetails"; $postfields["stats"] = true; //$postfields["clientid"] = Application_Model_Preference::GetClientId(); @@ -218,7 +233,7 @@ class BillingController extends Zend_Controller_Action { $query_string = ""; foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; - $arr = self::makeRequest($url, $query_string); + $arr = self::makeRequest($credentials["url"], $query_string); return $arr["client"]; } catch (Exception $e) { Logging::info($e->getMessage()); diff --git a/airtime_mvc/application/views/scripts/billing/client.phtml b/airtime_mvc/application/views/scripts/billing/client.phtml index d3850cfc2..980288c81 100644 --- a/airtime_mvc/application/views/scripts/billing/client.phtml +++ b/airtime_mvc/application/views/scripts/billing/client.phtml @@ -1,3 +1,8 @@
+errorMessage)) {?> +
errorMessage ?>
+successMessage)) {?> +
successMessage ?>
+ form ?>
\ No newline at end of file From 4179123ce04a50264de10e4466efb672b2ed4ca7 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 20 Jun 2014 16:41:48 -0400 Subject: [PATCH 130/285] Set up CORS for microsite autologin after signup --- .../application/controllers/LoginController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/airtime_mvc/application/controllers/LoginController.php b/airtime_mvc/application/controllers/LoginController.php index f5c6a01d0..0ddb17d2d 100644 --- a/airtime_mvc/application/controllers/LoginController.php +++ b/airtime_mvc/application/controllers/LoginController.php @@ -15,6 +15,16 @@ class LoginController extends Zend_Controller_Action $request = $this->getRequest(); + //Allow AJAX requests from www.airtime.pro. We use this to automatically login users + //after they sign up from the microsite. + $response = $this->getResponse()->setHeader('Access-Control-Allow-Origin', '*'); + $origin = $request->getHeader('Origin'); + if (($origin != "") && (!in_array($origin, array("http://www.airtime.pro", "https://www.airtime.pro")))) + { + //Don't allow CORS from other domains to prevent XSS. + throw new Zend_Controller_Action_Exception('Forbidden', 403); + } + Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA')); if (Zend_Auth::getInstance()->hasIdentity()) { From f6a4a9d0d09c79f5076d9779e83191420fcaecca Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 20 Jun 2014 16:54:05 -0400 Subject: [PATCH 131/285] Removed invalid client id - for testing purposes --- airtime_mvc/application/controllers/BillingController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 50af88b03..3747b2ee7 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -54,6 +54,7 @@ class BillingController extends Zend_Controller_Action { foreach ($clientfields AS $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; $result = $this->makeRequest($credentials["url"], $client_query_string); + Logging::info($result); if ($result["result"] == "error") { $this->setErrorMessage(); $this->view->form = $form; @@ -124,7 +125,7 @@ class BillingController extends Zend_Controller_Action { $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "updateclient"; //$postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["clientid"] = 18460000000; + $postfields["clientid"] = 1846; $postfields["responsetype"] = "json"; $postfields = array_merge($postfields, $formData); unset($postfields["password2verify"]); From 5d0ea2d01540e3aeb0618be28d2866c882925db6 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 20 Jun 2014 17:25:05 -0400 Subject: [PATCH 132/285] Add billing section to main menu --- airtime_mvc/application/configs/ACL.php | 2 +- .../application/configs/navigation.php | 28 +++++++++++++++++++ .../application/layouts/scripts/layout.phtml | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index fe0c5b425..ff65a9192 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -59,7 +59,7 @@ $ccAcl->allow('G', 'index') ->allow('A', 'user') ->allow('A', 'systemstatus') ->allow('A', 'preference') - ->allow('A', 'billing'); + ->allow('S', 'billing'); $aclPlugin = new Zend_Controller_Plugin_Acl($ccAcl); diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index f3149f146..87314135a 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -134,6 +134,34 @@ $pages = array( 'resource' => 'dashboard' ) ) + ), + array( + 'label' => _('Billing'), + 'uri' => '#', + 'resource' => 'billing', + 'pages' => array( + array( + 'label' => _('Account Details'), + 'module' => 'default', + 'controller' => 'billing', + 'action' => 'client', + 'resource' => 'billing' + ), + array( + 'label' => _('Account Plans'), + 'module' => 'default', + 'controller' => 'billing', + 'action' => 'upgrade', + 'resource' => 'billing' + ), + array( + 'label' => _('View Invocices'), + 'module' => 'default', + 'controller' => 'billing', + 'action' => 'invoices', + 'resource' => 'billing' + ) + ) ) ); diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index 6fef87157..ce67531c1 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -24,7 +24,7 @@
  • - >Upgrade  + >escape($this->loggedInAs()); ?> | >
  • From 25e4036d2f422fd5161a5488535274c478a74ad8 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 20 Jun 2014 17:29:56 -0400 Subject: [PATCH 133/285] typo --- airtime_mvc/application/configs/navigation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index 87314135a..5b7e4e049 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -155,7 +155,7 @@ $pages = array( 'resource' => 'billing' ), array( - 'label' => _('View Invocices'), + 'label' => _('View Invoices'), 'module' => 'default', 'controller' => 'billing', 'action' => 'invoices', From 0eab0c609b94b6dee2cb24e416a7c2e86c67cb0b Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 20 Jun 2014 17:43:20 -0400 Subject: [PATCH 134/285] Permissions fixes for Super Admin users --- airtime_mvc/application/controllers/LibraryController.php | 8 ++++---- .../application/controllers/ScheduleController.php | 8 ++++---- .../application/controllers/WebstreamController.php | 2 +- airtime_mvc/application/models/Block.php | 2 +- airtime_mvc/application/models/Playlist.php | 2 +- airtime_mvc/application/models/StoredFile.php | 2 +- airtime_mvc/application/models/User.php | 5 +++-- airtime_mvc/application/models/airtime/CcSubjs.php | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 41ab24eaa..42699e9bc 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -83,7 +83,7 @@ class LibraryController extends Zend_Controller_Action $obj = new $objInfo['className']($obj_sess->id); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if ($isAdminOrPM || $obj->getCreatorId() == $userInfo->id) { $this->view->obj = $obj; @@ -186,7 +186,7 @@ class LibraryController extends Zend_Controller_Action //Open a jPlayer window and play the audio clip. $menu["play"] = array("name"=> _("Preview"), "icon" => "play", "disabled" => false); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); @@ -302,7 +302,7 @@ class LibraryController extends Zend_Controller_Action $mediaItems = $this->_getParam('media', null); $user = Application_Model_User::getCurrentUser(); - //$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + //$isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $files = array(); $playlists = array(); @@ -418,7 +418,7 @@ class LibraryController extends Zend_Controller_Action public function editFileMdAction() { $user = Application_Model_User::getCurrentUser(); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $request = $this->getRequest(); diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index a430e15e5..ec385f167 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -104,7 +104,7 @@ class ScheduleController extends Zend_Controller_Action $this->createShowFormAction(true); $user = Application_Model_User::getCurrentUser(); - if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { + if ($user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $this->view->preloadShowForm = true; } @@ -133,7 +133,7 @@ class ScheduleController extends Zend_Controller_Action { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $editable = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $editable = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $calendar_interval = Application_Model_Preference::GetCalendarTimeScale(); Logging::info($calendar_interval); @@ -191,7 +191,7 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { + if ($user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { try { $show = new Application_Model_Show($showId); } catch (Exception $e) { @@ -586,7 +586,7 @@ class ScheduleController extends Zend_Controller_Action { $user = Application_Model_User::getCurrentUser(); - if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { + if ($user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $id = $this->_getParam('id'); try { diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index 8eb9a2ac5..1d94923c3 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -88,7 +88,7 @@ class WebstreamController extends Zend_Controller_Action public function isAuthorized($webstream_id) { $user = Application_Model_User::getCurrentUser(); - if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { + if ($user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { return true; } diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index babef06a5..8ea3593b1 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1038,7 +1038,7 @@ SQL; { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); // get only the files from the blocks // we are about to delete diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 7a7573d2a..90baaf621 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -987,7 +987,7 @@ SQL; { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); // get only the files from the playlists // we are about to delete diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index e30851e26..8031ba5c4 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -379,7 +379,7 @@ SQL; $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if (!$isAdminOrPM && $this->getFileOwnerId() != $user->getId()) { throw new FileNoPermissionException(); } diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index dc1cd49c8..14bb9491d 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -60,8 +60,9 @@ class Application_Model_User $type = $this->getType(); $result = false; - if ($type === UTYPE_ADMIN || - $type === UTYPE_PROGRAM_MANAGER || + if ($this->isAdmin() || + $this->isSuperAdmin() || + $this->isPM() || self::isHostOfShow($p_showId)) { $result = true; } diff --git a/airtime_mvc/application/models/airtime/CcSubjs.php b/airtime_mvc/application/models/airtime/CcSubjs.php index 78fd56d9e..9cba6165e 100644 --- a/airtime_mvc/application/models/airtime/CcSubjs.php +++ b/airtime_mvc/application/models/airtime/CcSubjs.php @@ -15,7 +15,7 @@ class CcSubjs extends BaseCcSubjs { public function isAdminOrPM() { - return $this->type === UTYPE_ADMIN || $this->type === UTYPE_PROGRAM_MANAGER; + return $this->type === UTYPE_ADMIN === UTYPE_SUPERADMIN || $this->type === UTYPE_ADMIN || $this->type === UTYPE_PROGRAM_MANAGER; } public function isHostOfShow($showId) From 9a84bdfda1cdffec6255191ac4fe1a624228041d Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 20 Jun 2014 17:44:30 -0400 Subject: [PATCH 135/285] Fixed syntax error --- airtime_mvc/application/models/airtime/CcSubjs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/airtime/CcSubjs.php b/airtime_mvc/application/models/airtime/CcSubjs.php index 9cba6165e..7fe6289f1 100644 --- a/airtime_mvc/application/models/airtime/CcSubjs.php +++ b/airtime_mvc/application/models/airtime/CcSubjs.php @@ -15,7 +15,7 @@ class CcSubjs extends BaseCcSubjs { public function isAdminOrPM() { - return $this->type === UTYPE_ADMIN === UTYPE_SUPERADMIN || $this->type === UTYPE_ADMIN || $this->type === UTYPE_PROGRAM_MANAGER; + return $this->type === UTYPE_SUPERADMIN || $this->type === UTYPE_ADMIN || $this->type === UTYPE_PROGRAM_MANAGER; } public function isHostOfShow($showId) From 18e7707d8fde752737dce121e46766aa9a59bca3 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 20 Jun 2014 18:10:59 -0400 Subject: [PATCH 136/285] Trying to fix my commit again --- .../public/js/airtime/schedule/full-calendar-functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index a178159ca..01b1096d5 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -35,7 +35,7 @@ function makeTimeStamp(date){ function dayClick(date, allDay, jsEvent, view){ // The show from will be preloaded if the user is admin or program manager. // Hence, if the user if DJ then it won't open anything. - if(userType == "A" || userType == "P"){ + if(userType == "S" || userType == "A" || userType == "P"){ var now, today, selected, chosenDate, chosenTime; now = adjustDateToServerDate(new Date(), serverTimezoneOffset); @@ -163,7 +163,7 @@ function viewDisplay( view ) { if(($("#add-show-form").length == 1) && ($("#add-show-form").css('display')=='none') && ($('.fc-header-left > span').length == 5)) { //userType is defined in bootstrap.php, and is derived from the currently logged in user. - if(userType == "A" || userType == "P"){ + if(userType == "S" || userType == "A" || userType == "P"){ makeAddShowButton(); } } From 6302e3b3359afcfc1108735b1645bf33ca06c33d Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 23 Jun 2014 13:24:28 -0400 Subject: [PATCH 137/285] Fix CORS with Chrome --- .../application/controllers/LoginController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/LoginController.php b/airtime_mvc/application/controllers/LoginController.php index 0ddb17d2d..7c18f5dc6 100644 --- a/airtime_mvc/application/controllers/LoginController.php +++ b/airtime_mvc/application/controllers/LoginController.php @@ -17,9 +17,17 @@ class LoginController extends Zend_Controller_Action //Allow AJAX requests from www.airtime.pro. We use this to automatically login users //after they sign up from the microsite. + //Chrome sends the Origin header for all requests, so we whitelist the webserver's hostname as well. $response = $this->getResponse()->setHeader('Access-Control-Allow-Origin', '*'); $origin = $request->getHeader('Origin'); - if (($origin != "") && (!in_array($origin, array("http://www.airtime.pro", "https://www.airtime.pro")))) + if (($origin != "") && + (!in_array($origin, + array("http://www.airtime.pro", + "https://www.airtime.pro", + "http://" . $_SERVER['SERVER_NAME'], + "https://" . $_SERVER['SERVER_NAME'] + )) + )) { //Don't allow CORS from other domains to prevent XSS. throw new Zend_Controller_Action_Exception('Forbidden', 403); From 806525e28c287e63e24e0b5e6bb0e1f8a3757364 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 23 Jun 2014 17:04:23 -0400 Subject: [PATCH 138/285] Fetch service id from whmcs api for upgrades --- .../controllers/BillingController.php | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 3747b2ee7..34590a3e1 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -21,11 +21,12 @@ class BillingController extends Zend_Controller_Action { $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "upgradeproduct"; + //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["clientid"] = 1846; - //TODO: do not hardcode - //$postfields["serviceid"] = self::getClientInstanceId(); - $postfields["serviceid"] = "1678"; + + $postfields["serviceid"] = self::getClientServiceId(); + $postfields["type"] = "product"; $postfields["newproductid"] = $formData["newproductid"]; $postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"]; @@ -33,15 +34,17 @@ class BillingController extends Zend_Controller_Action { $postfields["responsetype"] = "json"; $upgrade_query_string = ""; - foreach ($postfields AS $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; //update client info $clientfields = array(); $clientfields["username"] = $credentials["username"]; $clientfields["password"] = md5($credentials["password"]); $clientfields["action"] = "updateclient"; + //$clientfields["clientid"] = Application_Model_Preference::GetClientId(); $clientfields["clientid"] = 1846; + $clientfields["responsetype"] = "json"; unset($formData["newproductid"]); unset($formData["newproductbillingcycle"]); @@ -51,17 +54,22 @@ class BillingController extends Zend_Controller_Action { unset($clientfields["password2verify"]); unset($clientfields["submit"]); $client_query_string = ""; - foreach ($clientfields AS $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; + foreach ($clientfields as $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; $result = $this->makeRequest($credentials["url"], $client_query_string); - Logging::info($result); + if ($result["result"] == "error") { $this->setErrorMessage(); $this->view->form = $form; } else { - //$result = $this->makeRequest($credentials["url"], $upgrade_query_string); - //self::viewInvoice($result["invoiceid"]); - self::viewInvoice(5108); + $result = $this->makeRequest($credentials["url"], $upgrade_query_string); + if ($result["result"] == "error") { + Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed. - ".$result["message"]); + $this->setErrorMessage(); + $this->view->form = $form; + } else { + self::viewInvoice($result["invoiceid"]); + } } } else { $this->view->form = $form; @@ -102,7 +110,7 @@ class BillingController extends Zend_Controller_Action { { $whmcsurl = "https://account.sourcefabric.com/dologin.php"; $autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"]; - $timestamp = time(); //whmcs timezone? + $timestamp = time(); $client = self::getClientDetails(); $email = $client["email"]; $hash = sha1($email.$timestamp.$autoauthkey); @@ -124,15 +132,17 @@ class BillingController extends Zend_Controller_Action { $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "updateclient"; + //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["clientid"] = 1846; + $postfields["responsetype"] = "json"; $postfields = array_merge($postfields, $formData); unset($postfields["password2verify"]); unset($postfields["submit"]); $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = $this->makeRequest($credentials["url"], $query_string); @@ -165,7 +175,7 @@ class BillingController extends Zend_Controller_Action { //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); $this->view->invoices = $result["invoices"]["invoice"]; @@ -178,9 +188,10 @@ class BillingController extends Zend_Controller_Action { self::viewInvoice($invoice_id); } - //TODO: this does not return a service id. why? - private static function getClientInstanceId() + private static function getClientServiceId() { + $service_id = null; + $credentials = self::getAPICredentials(); $postfields = array(); @@ -192,10 +203,21 @@ class BillingController extends Zend_Controller_Action { //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); - Logging::info($result); + if (empty($result["products"])) { + Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed - Could not find service id"); + } else { + foreach ($result["products"]["product"] as $product) { + if (array_key_exists("groupname", $product) && $product["groupname"] == "Airtime") { + $service_id = $product["id"]; + } + break; + } + } + + return $service_id; } public static function getProducts() @@ -211,7 +233,7 @@ class BillingController extends Zend_Controller_Action { $postfields["gid"] = "15"; $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); return $result["products"]["product"]; @@ -232,7 +254,7 @@ class BillingController extends Zend_Controller_Action { $postfields["responsetype"] = "json"; $query_string = ""; - foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $arr = self::makeRequest($credentials["url"], $query_string); return $arr["client"]; From 73724bdd042f2fe9c4be2f90c36f6a4292c86054 Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 24 Jun 2014 12:46:11 -0400 Subject: [PATCH 139/285] Custom fields were not saving --- .../application/controllers/BillingController.php | 7 +++++-- airtime_mvc/application/forms/BillingClient.php | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 34590a3e1..92592ccab 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -125,13 +125,16 @@ class BillingController extends Zend_Controller_Action { if ($request->isPost()) { $formData = $request->getPost(); if ($form->isValid($formData)) { - + $credentials = self::getAPICredentials(); $postfields = array(); $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "updateclient"; + + $postfields["customfields"] = base64_encode(serialize($formData["customfields"])); + unset($formData["customfields"]); //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["clientid"] = 1846; @@ -140,7 +143,7 @@ class BillingController extends Zend_Controller_Action { $postfields = array_merge($postfields, $formData); unset($postfields["password2verify"]); unset($postfields["submit"]); - + $query_string = ""; foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; diff --git a/airtime_mvc/application/forms/BillingClient.php b/airtime_mvc/application/forms/BillingClient.php index 2b889a52e..d0cb60729 100644 --- a/airtime_mvc/application/forms/BillingClient.php +++ b/airtime_mvc/application/forms/BillingClient.php @@ -140,15 +140,16 @@ class Application_Form_BillingClient extends Zend_Form $this->addElement($securityqans); foreach ($client["customfields"] as $field) { - if ($field["id"] == 7) { + if ($field["id"] == "7") { $vatvalue = $field["value"]; - } elseif ($field["id"] == 71) { + } elseif ($field["id"] == "71") { $subscribevalue = $field["value"]; } } - $vat = new Zend_Form_Element_Text('customfield7'); + $vat = new Zend_Form_Element_Text("7"); $vat->setLabel(_('VAT/Tax ID (EU only)')) + ->setBelongsTo('customfields') ->setValue($vatvalue) ->setAttrib('class', 'input_text') //->setRequired(true) @@ -156,9 +157,10 @@ class Application_Form_BillingClient extends Zend_Form ->addFilter('StringTrim'); $this->addElement($vat); - $subscribe = new Zend_Form_Element_Checkbox('customfield71'); + $subscribe = new Zend_Form_Element_Checkbox('71'); $subscribe->setLabel(_('Subscribe to Sourcefabric newsletter')) ->setValue($subscribevalue) + ->setBelongsTo('customfields') ->setAttrib('class', 'input_text') ->setRequired(true) ->addValidator($notEmptyValidator) From 5d69ba5f91cb6d0da5675d6ac1a885c9dd5abf5a Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 24 Jun 2014 12:51:02 -0400 Subject: [PATCH 140/285] Custom fields were not saving --- airtime_mvc/application/controllers/BillingController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 92592ccab..4ade2cd6f 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -45,6 +45,9 @@ class BillingController extends Zend_Controller_Action { //$clientfields["clientid"] = Application_Model_Preference::GetClientId(); $clientfields["clientid"] = 1846; + $clientfields["customfields"] = base64_encode(serialize($formData["customfields"])); + unset($formData["customfields"]); + $clientfields["responsetype"] = "json"; unset($formData["newproductid"]); unset($formData["newproductbillingcycle"]); From 8c205924233de8efa4ea86c991fb122993494583 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 24 Jun 2014 15:52:43 -0400 Subject: [PATCH 141/285] Start of form customization for billing --- .../controllers/BillingController.php | 72 ++++++----------- .../application/forms/BillingClient.php | 2 +- .../forms/BillingUpgradeDowngrade.php | 11 ++- .../views/scripts/billing/upgrade.phtml | 80 ++++++++++++++++++- airtime_mvc/public/css/billing.css | 33 ++++++++ 5 files changed, 144 insertions(+), 54 deletions(-) create mode 100644 airtime_mvc/public/css/billing.css diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 4ade2cd6f..6cb18550d 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -9,6 +9,10 @@ class BillingController extends Zend_Controller_Action { public function upgradeAction() { + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + $this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']); + $request = $this->getRequest(); $form = new Application_Form_BillingUpgradeDowngrade(); if ($request->isPost()) { @@ -21,12 +25,11 @@ class BillingController extends Zend_Controller_Action { $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "upgradeproduct"; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["clientid"] = 1846; - - $postfields["serviceid"] = self::getClientServiceId(); - + //TODO: do not hardcode + //$postfields["serviceid"] = self::getClientInstanceId(); + $postfields["serviceid"] = "1678"; $postfields["type"] = "product"; $postfields["newproductid"] = $formData["newproductid"]; $postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"]; @@ -34,20 +37,15 @@ class BillingController extends Zend_Controller_Action { $postfields["responsetype"] = "json"; $upgrade_query_string = ""; - foreach ($postfields as $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; //update client info $clientfields = array(); $clientfields["username"] = $credentials["username"]; $clientfields["password"] = md5($credentials["password"]); $clientfields["action"] = "updateclient"; - //$clientfields["clientid"] = Application_Model_Preference::GetClientId(); $clientfields["clientid"] = 1846; - - $clientfields["customfields"] = base64_encode(serialize($formData["customfields"])); - unset($formData["customfields"]); - $clientfields["responsetype"] = "json"; unset($formData["newproductid"]); unset($formData["newproductbillingcycle"]); @@ -57,22 +55,17 @@ class BillingController extends Zend_Controller_Action { unset($clientfields["password2verify"]); unset($clientfields["submit"]); $client_query_string = ""; - foreach ($clientfields as $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; + foreach ($clientfields AS $k=>$v) $client_query_string .= "$k=".urlencode($v)."&"; $result = $this->makeRequest($credentials["url"], $client_query_string); - + Logging::info($result); if ($result["result"] == "error") { $this->setErrorMessage(); $this->view->form = $form; } else { - $result = $this->makeRequest($credentials["url"], $upgrade_query_string); - if ($result["result"] == "error") { - Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed. - ".$result["message"]); - $this->setErrorMessage(); - $this->view->form = $form; - } else { - self::viewInvoice($result["invoiceid"]); - } + //$result = $this->makeRequest($credentials["url"], $upgrade_query_string); + //self::viewInvoice($result["invoiceid"]); + self::viewInvoice(5108); } } else { $this->view->form = $form; @@ -113,7 +106,7 @@ class BillingController extends Zend_Controller_Action { { $whmcsurl = "https://account.sourcefabric.com/dologin.php"; $autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"]; - $timestamp = time(); + $timestamp = time(); //whmcs timezone? $client = self::getClientDetails(); $email = $client["email"]; $hash = sha1($email.$timestamp.$autoauthkey); @@ -128,27 +121,22 @@ class BillingController extends Zend_Controller_Action { if ($request->isPost()) { $formData = $request->getPost(); if ($form->isValid($formData)) { - + $credentials = self::getAPICredentials(); $postfields = array(); $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "updateclient"; - - $postfields["customfields"] = base64_encode(serialize($formData["customfields"])); - unset($formData["customfields"]); - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["clientid"] = 1846; - $postfields["responsetype"] = "json"; $postfields = array_merge($postfields, $formData); unset($postfields["password2verify"]); unset($postfields["submit"]); - + $query_string = ""; - foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = $this->makeRequest($credentials["url"], $query_string); @@ -181,7 +169,7 @@ class BillingController extends Zend_Controller_Action { //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; - foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); $this->view->invoices = $result["invoices"]["invoice"]; @@ -194,10 +182,9 @@ class BillingController extends Zend_Controller_Action { self::viewInvoice($invoice_id); } - private static function getClientServiceId() + //TODO: this does not return a service id. why? + private static function getClientInstanceId() { - $service_id = null; - $credentials = self::getAPICredentials(); $postfields = array(); @@ -209,21 +196,10 @@ class BillingController extends Zend_Controller_Action { //$postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; - foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); - if (empty($result["products"])) { - Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed - Could not find service id"); - } else { - foreach ($result["products"]["product"] as $product) { - if (array_key_exists("groupname", $product) && $product["groupname"] == "Airtime") { - $service_id = $product["id"]; - } - break; - } - } - - return $service_id; + Logging::info($result); } public static function getProducts() @@ -239,7 +215,7 @@ class BillingController extends Zend_Controller_Action { $postfields["gid"] = "15"; $query_string = ""; - foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); return $result["products"]["product"]; @@ -260,7 +236,7 @@ class BillingController extends Zend_Controller_Action { $postfields["responsetype"] = "json"; $query_string = ""; - foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $arr = self::makeRequest($credentials["url"], $query_string); return $arr["client"]; diff --git a/airtime_mvc/application/forms/BillingClient.php b/airtime_mvc/application/forms/BillingClient.php index d0cb60729..8ade507f2 100644 --- a/airtime_mvc/application/forms/BillingClient.php +++ b/airtime_mvc/application/forms/BillingClient.php @@ -4,7 +4,7 @@ require_once 'Zend/Locale.php'; class Application_Form_BillingClient extends Zend_Form { public function init() - { + { /*$this->setDecorators(array( array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/ $client = BillingController::getClientDetails(); diff --git a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php index 8a7d8a084..10f2b8be7 100644 --- a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php +++ b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php @@ -6,7 +6,7 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form $productPrices = array(); $productTypes = array(); $products = BillingController::getProducts(); - + foreach ($products as $k => $p) { $productPrices[$p["name"]] = array( "monthly" => $p["pricing"]["USD"]["monthly"], @@ -18,23 +18,26 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form //$currentPlanType = ucfirst(Application_Model_Preference::GetPlanLevel()); $currentPlanType = "Hobbyist"; if (($key = array_search($currentPlanType, $productTypes)) !== false) { - unset($productTypes[$key]); + //unset($productTypes[$key]); } $pid = new Zend_Form_Element_Radio('newproductid'); $pid->setLabel(_('Plan type:')) ->setMultiOptions($productTypes) + ->setRequired(true) ->setValue(26); - $this->addElement($pid); - + $this->addElement($pid); + $billingcycle = new Zend_Form_Element_Radio('newproductbillingcycle'); $billingcycle->setLabel(_('Billing cycle:')) ->setMultiOptions(array('monthly' => 'monthly', 'annually' => 'annually')) + ->setRequired(true) ->setValue('monthly'); $this->addElement($billingcycle); $paymentmethod = new Zend_Form_Element_Radio('paymentmethod'); $paymentmethod->setLabel(_('Payment method:')) + ->setRequired(true) ->setMultiOptions(array( 'paypal' => _('PayPal'), 'tco' => _('Credit Card via 2Checkout'))) diff --git a/airtime_mvc/application/views/scripts/billing/upgrade.phtml b/airtime_mvc/application/views/scripts/billing/upgrade.phtml index 6d40d3b0d..c111765b5 100644 --- a/airtime_mvc/application/views/scripts/billing/upgrade.phtml +++ b/airtime_mvc/application/views/scripts/billing/upgrade.phtml @@ -1,8 +1,86 @@ +form; + $form->setAttrib('id', 'upgrade-downgrade'); +?>
    +

    Account Plans

    +
    +pricing grid here +
    errorMessage)) {?>
    errorMessage ?>
    Plan Level:
    -form ?> + + + +
    + +
    + newproductid ?> +
    +
    + newproductbillingcycle ?> +
    +
    + paymentmethod ?> +
    + +
    + getSubform("billing_client_info") ?> +
    + firstname?> +
    +
    + lastname?> +
    +
    + companyname?> +
    +
    + email?> +
    +
    + address1?> +
    +
    + address2?> +
    +
    + city?> +
    +
    + state?> +
    +
    + postcode?> +
    +
    + country?> +
    +
    + phonenumber?> +
    +
    + securityqid?> +
    +
    + securityqans?> +
    +
    + getElement("7"); ?> +
    +
    + getElement("71"); ?> +
    +
    + password2?> +
    +
    + password2verify?> +
    + +




    \ No newline at end of file diff --git a/airtime_mvc/public/css/billing.css b/airtime_mvc/public/css/billing.css new file mode 100644 index 000000000..da9ab49be --- /dev/null +++ b/airtime_mvc/public/css/billing.css @@ -0,0 +1,33 @@ +@CHARSET "UTF-8"; + +#upgrade-downgrade dl +{ + width: 300px; +} + +#upgrade-downgrade dt, #upgrade-downgrade dd +{ + margin: 0px; +} + +#upgrade-downgrade dd +{ + margin-bottom: 10px; +} + +#plantype +{ + float: left; + +} + +#billingcycle +{ + float: left; +} + +#paymentmethod +{ + float: left; + +} \ No newline at end of file From bfb5631105600311caf8f9e412ebf3c693b51f0c Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 24 Jun 2014 16:23:23 -0400 Subject: [PATCH 142/285] Removed hardcoded client ids. Added a function that calculates vat and adds it to an invoice --- .../controllers/BillingController.php | 74 +++++++++++++++---- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 4ade2cd6f..5406ffee5 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -12,7 +12,15 @@ class BillingController extends Zend_Controller_Action { $request = $this->getRequest(); $form = new Application_Form_BillingUpgradeDowngrade(); if ($request->isPost()) { - //$formData = $form->getValues(); + + /* + * TODO: determine if VAT shoould be charged on the invoice or not. + * We'll need to check if a VAT number was supplied in the form and if so, + * validate it somehow. We'll also need to make sure the country given is + * in the EU + */ + $apply_vat = false; + $formData = $request->getPost(); if ($form->isValid($formData)) { $credentials = self::getAPICredentials(); @@ -22,8 +30,7 @@ class BillingController extends Zend_Controller_Action { $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "upgradeproduct"; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["clientid"] = 1846; + $postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["serviceid"] = self::getClientServiceId(); @@ -37,13 +44,13 @@ class BillingController extends Zend_Controller_Action { foreach ($postfields as $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&"; //update client info + $clientfields = array(); $clientfields["username"] = $credentials["username"]; $clientfields["password"] = md5($credentials["password"]); $clientfields["action"] = "updateclient"; - //$clientfields["clientid"] = Application_Model_Preference::GetClientId(); - $clientfields["clientid"] = 1846; + $clientfields["clientid"] = Application_Model_Preference::GetClientId(); $clientfields["customfields"] = base64_encode(serialize($formData["customfields"])); unset($formData["customfields"]); @@ -71,6 +78,9 @@ class BillingController extends Zend_Controller_Action { $this->setErrorMessage(); $this->view->form = $form; } else { + if ($apply_vat) { + $this->addVatToInvoice($result["invoiceid"]); + } self::viewInvoice($result["invoiceid"]); } } @@ -82,6 +92,47 @@ class BillingController extends Zend_Controller_Action { } } + private function addVatToInvoice($invoice_id) + { + $credentials = self::getAPICredentials(); + + //First we need to get the invoice details: sub total, and total + //so we can calcuate the amount of VAT to add + $invoicefields = array(); + $invoicefields["username"] = $credentials["username"]; + $invoicefields["password"] = md5($credentials["password"]); + $invoicefields["action"] = "getinvoice"; + $invoicefields["invoiceid"] = $invoice_id; + $invoicefields["responsetype"] = "json"; + + $invoice_query_string = ""; + foreach ($invoicefields as $k=>$v) $invoice_query_string .= "$k=".urlencode($v)."&"; + + //TODO: error checking + $result = $this->makeRequest($credentials["url"], $invoice_query_string); + + $vat_rate = 19.00; + $vat_amount = $result["subtotal"] * ($vat_rate/100); + $invoice_total = $result["total"] + $vat_amount; + + //Second, update the invoice with the VAT amount and updated total + $postfields = array(); + $postfields["username"] = $credentials["username"]; + $postfields["password"] = md5($credentials["password"]); + $postfields["action"] = "updateinvoice"; + $postfields["invoiceid"] = $invoice_id; + $postfields["tax"] = "$vat_amount"; + $postfields["taxrate"] = "$vat_rate"; + $postfields["total"] = "$invoice_total"; + $postfields["responsetype"] = "json"; + + $query_string = ""; + foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; + + //TODO: error checking + $result = $this->makeRequest($credentials["url"], $query_string); + } + private function setErrorMessage($msg=null) { if (!is_null($msg)) { @@ -139,8 +190,7 @@ class BillingController extends Zend_Controller_Action { $postfields["customfields"] = base64_encode(serialize($formData["customfields"])); unset($formData["customfields"]); - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["clientid"] = 1846; + $postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["responsetype"] = "json"; $postfields = array_merge($postfields, $formData); @@ -177,13 +227,13 @@ class BillingController extends Zend_Controller_Action { $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getinvoices"; $postfields["responsetype"] = "json"; - $postfields["userid"] = 1846; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); + $postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $result = self::makeRequest($credentials["url"], $query_string); + $this->view->invoices = $result["invoices"]["invoice"]; } @@ -205,8 +255,7 @@ class BillingController extends Zend_Controller_Action { $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getclientsproducts"; $postfields["responsetype"] = "json"; - $postfields["clientid"] = 1846; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); + $postfields["clientid"] = Application_Model_Preference::GetClientId(); $query_string = ""; foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; @@ -255,8 +304,7 @@ class BillingController extends Zend_Controller_Action { $postfields["password"] = md5($credentials["password"]); $postfields["action"] = "getclientsdetails"; $postfields["stats"] = true; - //$postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["clientid"] = 1846; + $postfields["clientid"] = Application_Model_Preference::GetClientId(); $postfields["responsetype"] = "json"; $query_string = ""; From 8a5a7968583cc996011c0afa49287406d541ce1a Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 24 Jun 2014 16:46:10 -0400 Subject: [PATCH 143/285] Undo session fix temporarily until issues resolved --- airtime_mvc/application/models/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Auth.php b/airtime_mvc/application/models/Auth.php index 5fe65084f..d12ebb61e 100644 --- a/airtime_mvc/application/models/Auth.php +++ b/airtime_mvc/application/models/Auth.php @@ -117,6 +117,6 @@ class Application_Model_Auth */ public static function pinSessionToClient($auth) { - $auth->setStorage(new Zend_Auth_Storage_Session('Airtime' . $_SERVER['SERVER_NAME'] . Application_Model_Preference::GetClientId())); + //$auth->setStorage(new Zend_Auth_Storage_Session('Airtime' . $_SERVER['SERVER_NAME'] . Application_Model_Preference::GetClientId())); } } From d92e5197e1afc92c599531b38d15a40087f340e2 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 25 Jun 2014 18:58:54 -0400 Subject: [PATCH 144/285] Design and overhaul of Account Plans screen * Basically working now except for VAT calculation * Includes pricing grid, basic total calculation * Revamped layout * Implemented getting the service ID in BillingController.php --- airtime_mvc/application/Bootstrap.php | 1 + airtime_mvc/application/configs/constants.php | 6 + .../controllers/BillingController.php | 71 +++++- .../controllers/WhmcsLoginController.php | 3 - .../application/forms/BillingClient.php | 4 +- .../forms/BillingUpgradeDowngrade.php | 18 +- .../views/scripts/billing/client.phtml | 1 + .../views/scripts/billing/upgrade.phtml | 225 +++++++++++++++--- .../views/scripts/partialviews/trialBox.phtml | 2 +- airtime_mvc/public/css/billing.css | 113 ++++++++- 10 files changed, 393 insertions(+), 51 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index fc9f6c7e4..d66c680c5 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -14,6 +14,7 @@ require_once "DateHelper.php"; require_once "OsPath.php"; require_once "Database.php"; require_once "Timezone.php"; +require_once "Auth.php"; require_once __DIR__.'/forms/helpers/ValidationTypes.php'; require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; require_once __DIR__.'/controllers/plugins/Maintenance.php'; diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index 9e2563d0f..69ce78d19 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -64,3 +64,9 @@ define('UI_BLOCK_SESSNAME', 'BLOCK');*/ define('SOUNDCLOUD_NOT_UPLOADED_YET' , -1); define('SOUNDCLOUD_PROGRESS' , -2); define('SOUNDCLOUD_ERROR' , -3); + + +//WHMCS integration +define("WHMCS_API_URL", "https://account.sourcefabric.com/includes/api.php"); +define("SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME", "Choose your domain"); + diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index ffe90234f..e8aeea0f5 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -12,6 +12,7 @@ class BillingController extends Zend_Controller_Action { $CC_CONFIG = Config::getConfig(); $baseUrl = Application_Common_OsPath::getBaseDir(); $this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']); + BillingController::ensureClientIdIsValid(); $request = $this->getRequest(); $form = new Application_Form_BillingUpgradeDowngrade(); @@ -35,7 +36,7 @@ class BillingController extends Zend_Controller_Action { $postfields["action"] = "upgradeproduct"; $postfields["clientid"] = Application_Model_Preference::GetClientId(); - $postfields["serviceid"] = self::getClientServiceId(); + $postfields["serviceid"] = self::getClientInstanceId(); $postfields["type"] = "product"; $postfields["newproductid"] = $formData["newproductid"]; $postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"]; @@ -175,6 +176,7 @@ class BillingController extends Zend_Controller_Action { { $request = $this->getRequest(); $form = new Application_Form_BillingClient(); + BillingController::ensureClientIdIsValid(); if ($request->isPost()) { $formData = $request->getPost(); if ($form->isValid($formData)) { @@ -218,6 +220,7 @@ class BillingController extends Zend_Controller_Action { public function invoicesAction() { + BillingController::ensureClientIdIsValid(); $credentials = self::getAPICredentials(); $postfields = array(); @@ -237,6 +240,7 @@ class BillingController extends Zend_Controller_Action { public function invoiceAction() { + BillingController::ensureClientIdIsValid(); $request = $this->getRequest(); $invoice_id = $request->getParam('invoiceid'); self::viewInvoice($invoice_id); @@ -259,10 +263,52 @@ class BillingController extends Zend_Controller_Action { $result = self::makeRequest($credentials["url"], $query_string); Logging::info($result); + + if ($_SERVER['SERVER_NAME'] == "airtime.localhost") { + return "1384"; + } + //This code must run on airtime.pro for it to work... it's trying to match + //the server's hostname with the client subdomain. + foreach ($result["products"] as $product) + { + if (strpos($product[0]["groupname"], "Airtime") === FALSE) + { + //Ignore non-Airtime products + continue; + } + else + { + if ($product[0]["status"] === "Active") { + $airtimeProduct = $product[0]; + $subdomain = ''; + + foreach ($airtimeProduct['customfields']['customfield'] as $customField) + { + if ($customField['name'] === SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME) + { + $subdomain = $customField['value']; + if (($subdomain . ".airtime.pro") === $_SERVER['SERVER_NAME']) + { + return $airtimeProduct['id']; + } + } + } + } + } + } + throw new Exception("Unable to match subdomain to a service ID"); } public static function getProducts() { + //Making this static to cache the products during a single HTTP request. + //This saves us roundtrips to WHMCS if getProducts() is called multiple times. + static $result = array(); + if (!empty($result)) + { + return $result["products"]["product"]; + } + $credentials = self::getAPICredentials(); $postfields = array(); @@ -279,6 +325,21 @@ class BillingController extends Zend_Controller_Action { $result = self::makeRequest($credentials["url"], $query_string); return $result["products"]["product"]; } + + public static function getProductPricesAndTypes() + { + $products = BillingController::getProducts(); + + foreach ($products as $k => $p) { + $productPrices[$p["name"]] = array( + "monthly" => $p["pricing"]["USD"]["monthly"], + "annually" => $p["pricing"]["USD"]["annually"] + ); + $productTypes[$p["pid"]] = $p["name"] . " ($" . $productPrices[$p['name']]['monthly'] . "/mo)"; + } + return array($productPrices, $productTypes); + } + public static function getClientDetails() { @@ -325,4 +386,12 @@ class BillingController extends Zend_Controller_Action { Logging::info($e->getMessage()); } } + + private static function ensureClientIdIsValid() + { + if (Application_Model_Preference::GetClientId() == null) + { + throw new Exception("Invalid client ID: " . Application_Model_Preference::GetClientId()); + } + } } \ No newline at end of file diff --git a/airtime_mvc/application/controllers/WhmcsLoginController.php b/airtime_mvc/application/controllers/WhmcsLoginController.php index 0f0e327de..2f78ce5ed 100644 --- a/airtime_mvc/application/controllers/WhmcsLoginController.php +++ b/airtime_mvc/application/controllers/WhmcsLoginController.php @@ -1,8 +1,5 @@ setLabel(_('Company Name:')) ->setValue($client["companyname"]) ->setAttrib('class', 'input_text') - ->setRequired(true) + ->setRequired(false) ->addValidator($notEmptyValidator) ->addFilter('StringTrim'); $this->addElement($companyname); @@ -85,7 +85,7 @@ class Application_Form_BillingClient extends Zend_Form $this->addElement($state); $postcode = new Zend_Form_Element_Text('postcode'); - $postcode->setLabel(_('Zip Code:')) + $postcode->setLabel(_('Zip Code / Postal Code:')) ->setValue($client["postcode"]) ->setAttrib('class', 'input_text') ->setRequired(true) diff --git a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php index 10f2b8be7..b89136689 100644 --- a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php +++ b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php @@ -4,17 +4,9 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form public function init() { $productPrices = array(); - $productTypes = array(); - $products = BillingController::getProducts(); - - foreach ($products as $k => $p) { - $productPrices[$p["name"]] = array( - "monthly" => $p["pricing"]["USD"]["monthly"], - "annualy" => $p["pricing"]["USD"]["annually"] - ); - $productTypes[$p["pid"]] = $p["name"]; - } - + $productTypes = array(); + list($productPrices, $productTypes) = BillingController::getProductPricesAndTypes(); + //$currentPlanType = ucfirst(Application_Model_Preference::GetPlanLevel()); $currentPlanType = "Hobbyist"; if (($key = array_search($currentPlanType, $productTypes)) !== false) { @@ -30,7 +22,7 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form $billingcycle = new Zend_Form_Element_Radio('newproductbillingcycle'); $billingcycle->setLabel(_('Billing cycle:')) - ->setMultiOptions(array('monthly' => 'monthly', 'annually' => 'annually')) + ->setMultiOptions(array('monthly' => 'Monthly', 'annually' => 'Annually')) ->setRequired(true) ->setValue('monthly'); $this->addElement($billingcycle); @@ -50,6 +42,8 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form $this->addElement($submit);*/ $client = new Application_Form_BillingClient(); + $client->removeElement("password2"); + $client->removeElement("password2verify"); $this->addSubForm($client, 'billing_client_info'); } } diff --git a/airtime_mvc/application/views/scripts/billing/client.phtml b/airtime_mvc/application/views/scripts/billing/client.phtml index 980288c81..a38b8f685 100644 --- a/airtime_mvc/application/views/scripts/billing/client.phtml +++ b/airtime_mvc/application/views/scripts/billing/client.phtml @@ -1,4 +1,5 @@
    +

    Account Details

    errorMessage)) {?>
    errorMessage ?>
    successMessage)) {?> diff --git a/airtime_mvc/application/views/scripts/billing/upgrade.phtml b/airtime_mvc/application/views/scripts/billing/upgrade.phtml index c111765b5..8a482ea80 100644 --- a/airtime_mvc/application/views/scripts/billing/upgrade.phtml +++ b/airtime_mvc/application/views/scripts/billing/upgrade.phtml @@ -1,19 +1,162 @@ form; $form->setAttrib('id', 'upgrade-downgrade'); + ?> -
    -

    Account Plans

    + + +
    +

    +

    -pricing grid here + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    HobbyistStarterPlusPremium
    1 Stream + 2 Streams + 2 Streams + 3 Streams +
    64kbps Stream Quality + 64kbps and 128kbps Stream Quality + 64kbps and 196kbps Stream Quality + 64kbps, 128kbps, and 196kbps Stream Quality +
    5 Listeners + 40 Listeners per stream + 100 Listeners per stream + 500 Listeners per stream +
    2GB Storage + 5GB Storage + 30GB Storage + 150GB Storage +
    Ticket, Email, Forum Support + Live Chat, Ticket, Email, Forum Support + Live Chat, Ticket, Email, Forum Support + Live Chat, Ticket, Email, Forum Support +
    + Save 15% if paid annually + Save 15% if paid annually + Save 15% if paid annually +
    + + + +
    -errorMessage)) {?> -
    errorMessage ?>
    - -
    Plan Level:
    - - + +

    Current Plan: +

    +

    Choose a plan:

    @@ -23,36 +166,51 @@ pricing grid here
    newproductbillingcycle ?>
    -
    - paymentmethod ?> +
    + Save 15% on annual plans (Hobbyist plan excluded). +
    +
    +
    Total:
    + +
    + Plus VAT if you are an EU resident without a valid VAT number.
    -
    +

    Enter your payment details:

    + errorMessage)) {?> +
    errorMessage ?>
    + + + getSubform("billing_client_info") ?> -
    +
    firstname?>
    -
    +
    lastname?>
    -
    +
    +
    companyname?>
    -
    +
    email?>
    -
    +
    +
    address1?>
    -
    +
    address2?> -
    -
    +
    +
    +
    city?>
    -
    +
    state?>
    +
    postcode?>
    @@ -68,19 +226,30 @@ pricing grid here
    securityqans?>
    +

    VAT will be added to your invoice if you are an EU resident without a valid VAT number.

    +
    getElement("7"); ?>
    +
    +
    - getElement("71"); ?> + getElement("71"); ?> +
    + getElement("71")->renderViewHelper(); ?> +
    + getElement("71")->renderLabel(); ?>
    -
    - password2?> +
    + +

    After submitting your order, you will be redirected to an invoice with payment buttons.

    -
    - password2verify?> +
    + paymentmethod ?>
    - + +
    + +
    -



    \ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml b/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml index 691d2983a..c0abffc89 100644 --- a/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml +++ b/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml @@ -6,7 +6,7 @@
    diff --git a/airtime_mvc/public/css/billing.css b/airtime_mvc/public/css/billing.css index da9ab49be..c34e8ad49 100644 --- a/airtime_mvc/public/css/billing.css +++ b/airtime_mvc/public/css/billing.css @@ -1,5 +1,28 @@ @CHARSET "UTF-8"; +.billing-panel +{ + width: 400px; + margin: 0 auto; + margin-bottom: 30px; +} + +#upgrade-downgrade +{ + border: 0px solid #000; + margin: 0 auto; + color: #000; +} + +#upgrade-downgrade label +{ + color: rgb(28,28,28); +} +#upgrade-downgrade label.disabled +{ + color: rgb(108,108,108); +} + #upgrade-downgrade dl { width: 300px; @@ -15,19 +38,101 @@ margin-bottom: 10px; } +.pricing-grid table +{ + border-spacing: 0px; + border-collapse: separate; + border: 1px solid #777; + width: 600px; + margin-left: -100px; + /*background-color: #555;*/ + table-layout: fixed; + margin-top: 20px; + margin-bottom: 20px; + box-shadow: 0px 5px 5px rgba(0,0,0,0.5); +} + +.pricing-grid td, .pricing-grid th +{ + border-bottom: 1px solid #999; + border-right: 1px solid #bbb; + background-color: #ccc; + padding: 10px; +} + +.pricing-grid th +{ + border-top-left-radius: 5px; + border-top-right-radius: 5px; + border: 0px; +} + + +.pricing-grid tr.price td +{ + text-align: right; + background-color: #ddd; + font-weight: bold; +} + +#current_plan +{ + text-align: center; +} + #plantype { - float: left; - + float: left; } #billingcycle { float: left; + margin-left: 30px; +} + +#billingcycle_disclaimer +{ + float: left; + margin-left: 30px; + width: 200px; +} + +#vat_disclaimer +{ + text-align: right; + font-size: 0.9em; + margin-bottom: 30px; +} + +#total_box +{ + text-align: right; + margin-top: 30px; + margin-bottom: 10px; + border: 1px solid #777; + background: #ccc; + padding: 5px; } #paymentmethod { - float: left; - +} + +.billing_col1, .billing_col2 +{ + float: left; + margin-right: 10px; +} + +.billing_checkbox +{ + float: left; + margin-right: 5px; + margin-bottom: 10px; +} + +#upgrade-downgrade input[type=submit] +{ + float: right; } \ No newline at end of file From fce6116d604626ba1bbe4347acc543b50b4c10ee Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 25 Jun 2014 20:01:14 -0400 Subject: [PATCH 145/285] Made the invoices view nice! --- .../controllers/BillingController.php | 8 +++++ .../views/scripts/billing/client.phtml | 4 +-- .../views/scripts/billing/invoices.phtml | 23 ++++++++++--- airtime_mvc/public/css/billing.css | 33 +++++++++++++++++++ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index e8aeea0f5..e5049d449 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -174,6 +174,10 @@ class BillingController extends Zend_Controller_Action { public function clientAction() { + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + $this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']); + $request = $this->getRequest(); $form = new Application_Form_BillingClient(); BillingController::ensureClientIdIsValid(); @@ -220,6 +224,10 @@ class BillingController extends Zend_Controller_Action { public function invoicesAction() { + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + $this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']); + BillingController::ensureClientIdIsValid(); $credentials = self::getAPICredentials(); diff --git a/airtime_mvc/application/views/scripts/billing/client.phtml b/airtime_mvc/application/views/scripts/billing/client.phtml index a38b8f685..5b89d280b 100644 --- a/airtime_mvc/application/views/scripts/billing/client.phtml +++ b/airtime_mvc/application/views/scripts/billing/client.phtml @@ -1,5 +1,5 @@ -
    -

    Account Details

    +
    +

    Billing Account Details

    errorMessage)) {?>
    errorMessage ?>
    successMessage)) {?> diff --git a/airtime_mvc/application/views/scripts/billing/invoices.phtml b/airtime_mvc/application/views/scripts/billing/invoices.phtml index ed1f13a74..d143441cc 100644 --- a/airtime_mvc/application/views/scripts/billing/invoices.phtml +++ b/airtime_mvc/application/views/scripts/billing/invoices.phtml @@ -1,9 +1,22 @@ -
    +
    +

    Invoices

    +

    and look for the \"Checkout\" button.")?>

    + + + + + + + invoices as $invoice) {?> - + + + + + + - + +
    Date IssuedDue DateLinkStatus
    ">View Invoice">
    \ No newline at end of file diff --git a/airtime_mvc/public/css/billing.css b/airtime_mvc/public/css/billing.css index c34e8ad49..9aaada3e3 100644 --- a/airtime_mvc/public/css/billing.css +++ b/airtime_mvc/public/css/billing.css @@ -135,4 +135,37 @@ #upgrade-downgrade input[type=submit] { float: right; +} + +#invoices_table +{ + margin: 0 auto; + border-spacing: 0px; + border-collapse: separate; + border: 1px solid #777; + /*background-color: #555;*/ + table-layout: fixed; + margin-top: 20px; + margin-bottom: 35px; + background: #ccc; +} + +#invoices_table tbody tr th +{ + border: 0px; +} + +#invoices_table .header +{ + box-shadow: 0px 2px 2px rgba(0,0,0,0.5); +} + +#invoices_table tr +{ + border: 1px solid #555; +} + +#invoices_table .unpaid +{ + color: #ff0000; } \ No newline at end of file From b36967a6905b3a99042ff617cbc7bc10120e0ac6 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 25 Jun 2014 20:32:41 -0400 Subject: [PATCH 146/285] Nicer auto-styling for the Billing Details form --- .../application/forms/BillingClient.php | 1 + .../views/scripts/billing/client.phtml | 5 +++++ airtime_mvc/public/css/billing.css | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/airtime_mvc/application/forms/BillingClient.php b/airtime_mvc/application/forms/BillingClient.php index 716bc36fd..5e6a2c252 100644 --- a/airtime_mvc/application/forms/BillingClient.php +++ b/airtime_mvc/application/forms/BillingClient.php @@ -8,6 +8,7 @@ class Application_Form_BillingClient extends Zend_Form /*$this->setDecorators(array( array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/ $client = BillingController::getClientDetails(); + $this->setAttrib("id", "clientdetails_form"); $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator(); $emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator(); diff --git a/airtime_mvc/application/views/scripts/billing/client.phtml b/airtime_mvc/application/views/scripts/billing/client.phtml index 5b89d280b..e57fb140b 100644 --- a/airtime_mvc/application/views/scripts/billing/client.phtml +++ b/airtime_mvc/application/views/scripts/billing/client.phtml @@ -1,3 +1,8 @@ +form->getElement("submit")->setAttrib("class", "right-align"); +$this->form->getElement("country")->setAttrib("class", "right-align"); +$this->form->getElement("securityqid")->setAttrib("class", "right-align"); +?>

    Billing Account Details

    errorMessage)) {?> diff --git a/airtime_mvc/public/css/billing.css b/airtime_mvc/public/css/billing.css index 9aaada3e3..88498a88f 100644 --- a/airtime_mvc/public/css/billing.css +++ b/airtime_mvc/public/css/billing.css @@ -168,4 +168,22 @@ #invoices_table .unpaid { color: #ff0000; +} + +/** This form is the separate one on the Billing Account Details page (BillingClient.php) */ +#clientdetails_form dt { + float: left; + clear: both; + width: 50%; + margin-bottom: 10px; +} +#clientdetails_form dd { + float: left; + margin-left: 0px; + margin-bottom: 10px; +} +#clientdetails_form .right-align +{ + /*text-align: right;*/ + width: 100%; } \ No newline at end of file From 94bbd3c8a59d158b56a481699abb7c572a679ad0 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Wed, 25 Jun 2014 20:36:08 -0400 Subject: [PATCH 147/285] Don't open trialbox My Account link in new window --- .../application/views/scripts/partialviews/trialBox.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml b/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml index c0abffc89..18873ce00 100644 --- a/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml +++ b/airtime_mvc/application/views/scripts/partialviews/trialBox.phtml @@ -6,7 +6,7 @@
    From 18c828defd0025bdd9981907981887a164cb450d Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 26 Jun 2014 17:31:34 -0400 Subject: [PATCH 148/285] Finished up VAT validation for Plans page --- .../controllers/BillingController.php | 144 +++++++++++++++++- .../views/scripts/billing/upgrade.phtml | 137 +++++++++++++++-- airtime_mvc/public/css/billing.css | 39 ++++- 3 files changed, 297 insertions(+), 23 deletions(-) diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index e5049d449..e5feb47b6 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -1,7 +1,18 @@ _helper->getHelper('AjaxContext'); + $ajaxContext->addActionContext('vat-validator', 'json') + ->addActionContext('is-country-in-eu', 'json') + ->initContext(); + } + public function indexAction() { @@ -24,12 +35,13 @@ class BillingController extends Zend_Controller_Action { * validate it somehow. We'll also need to make sure the country given is * in the EU */ - $apply_vat = false; - + $formData = $request->getPost(); if ($form->isValid($formData)) { $credentials = self::getAPICredentials(); + $apply_vat = BillingController::checkIfVatShouldBeApplied($formData["customfields"]["7"], $formData["country"]); + $postfields = array(); $postfields["username"] = $credentials["username"]; $postfields["password"] = md5($credentials["password"]); @@ -91,6 +103,124 @@ class BillingController extends Zend_Controller_Action { $this->view->form = $form; } } + + + public function isCountryInEuAction() + { + // Disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $request = $this->getRequest(); + if (!$request->isPost()) { + throw new Exception("Must POST data to isCountryInEuAction."); + } + $formData = $request->getPost(); + + //Set the return JSON value + $this->_helper->json(array("result"=>BillingController::isCountryInEU($formData["country"]))); + } + + public function vatValidatorAction() + { + // Disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $request = $this->getRequest(); + if (!$request->isPost()) { + throw new Exception("Must POST data to vatValidatorAction."); + } + $formData = $request->getPost(); + + $vatNumber = trim($formData["vatnumber"]); + if (empty($vatNumber)) { + $this->_helper->json(array("result"=>false)); + } + + //Set the return JSON value + $this->_helper->json(array("result"=>BillingController::checkIfVatShouldBeApplied($vatNumber, $formData["country"]))); + } + + /** + * @return True if VAT should be applied to the order, false otherwise. + */ + private static function checkIfVatShouldBeApplied($vatNumber, $countryCode) + { + if ($countryCode === 'UK') { + $countryCode = 'GB'; //VIES database has it as GB + } + //We don't charge you VAT if you're not in the EU + if (!BillingController::isCountryInEU($countryCode)) + { + return false; + } + + //So by here, we know you're in the EU. + + //No VAT number? Then we charge you VAT. + if (empty($vatNumber)) { + return true; + } + //Check if VAT number is valid + return BillingController::validateVATNumber($vatNumber, $countryCode); + } + + private static function isCountryInEU($countryCode) + { + $euCountryCodes = array('BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'EL', 'ES', 'FR', + 'HR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'AT', + 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'UK', 'GB'); + + if (!in_array($countryCode, $euCountryCodes)) { + return false; + } + return true; + } + + /** + * Check if an EU VAT number is valid, using the EU VIES validation web API. + * + * @param string $vatNumber - A VAT identifier (number), with or without the two letter country code at the + * start (either one works) . + * @param string $countryCode - A two letter country code + * @return boolean true if the VAT number is valid, false otherwise. + */ + private static function validateVATNumber($vatNumber, $countryCode) + { + $vatNumber = str_replace(array(' ', '.', '-', ',', ', '), '', trim($vatNumber)); + + //If the first two letters are a country code, use that as the country code and remove those letters. + $firstTwoCharacters = substr($vatNumber, 0, 2); + if (preg_match("/[a-zA-Z][a-zA-Z]/", $firstTwoCharacters) === 1) { + $countryCode = strtoupper($firstTwoCharacters); //The country code from the VAT number overrides your country. + $vatNumber = substr($vatNumber, 2); + } + $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"); + + if($client){ + $params = array('countryCode' => $countryCode, 'vatNumber' => $vatNumber); + try{ + $r = $client->checkVat($params); + if($r->valid == true){ + // VAT-ID is valid + return true; + } else { + // VAT-ID is NOT valid + return false; + } + } catch(SoapFault $e) { + Logging::error('VIES EU VAT validation error: '.$e->faultstring); + return false; + } + } else { + // Connection to host not possible, europe.eu down? + Logging::error('VIES EU VAT validation error: Host unreachable'); + return false; + } + return false; + } + private function addVatToInvoice($invoice_id) { @@ -111,8 +241,7 @@ class BillingController extends Zend_Controller_Action { //TODO: error checking $result = $this->makeRequest($credentials["url"], $invoice_query_string); - $vat_rate = 19.00; - $vat_amount = $result["subtotal"] * ($vat_rate/100); + $vat_amount = $result["subtotal"] * (VAT_RATE/100); $invoice_total = $result["total"] + $vat_amount; //Second, update the invoice with the VAT amount and updated total @@ -254,7 +383,6 @@ class BillingController extends Zend_Controller_Action { self::viewInvoice($invoice_id); } - //TODO: this does not return a service id. why? private static function getClientInstanceId() { $credentials = self::getAPICredentials(); @@ -272,11 +400,15 @@ class BillingController extends Zend_Controller_Action { $result = self::makeRequest($credentials["url"], $query_string); Logging::info($result); + //XXX: Debugging / local testing if ($_SERVER['SERVER_NAME'] == "airtime.localhost") { return "1384"; } + //This code must run on airtime.pro for it to work... it's trying to match - //the server's hostname with the client subdomain. + //the server's hostname with the client subdomain. Once it finds a match + //between the product and the server's hostname/subdomain, then it + //returns the ID of that product (aka. the service ID of an Airtime instance) foreach ($result["products"] as $product) { if (strpos($product[0]["groupname"], "Airtime") === FALSE) diff --git a/airtime_mvc/application/views/scripts/billing/upgrade.phtml b/airtime_mvc/application/views/scripts/billing/upgrade.phtml index 8a482ea80..e0792d523 100644 --- a/airtime_mvc/application/views/scripts/billing/upgrade.phtml +++ b/airtime_mvc/application/views/scripts/billing/upgrade.phtml @@ -4,9 +4,14 @@ ?>