Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolence authored Oct 19, 2017
1 parent ba9cd15 commit a174ec7
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 3 deletions.
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# skysoft
skylabase voip softphones
the project is an open source project aimed at developing voip application for skylabase intercom system
Text-to-Vote
============

Text-to-Vote is a simple web app that allows you to do realtime polling through
SMS.

Text-to-Vote works with the Twilio API, so you'll need an account and phone
number at Twilio before you can get started. Twilio sells simple, pay as you
go phone services, and you can sign up for a free account with $30 of free
credits at [http://www.twilio.com](http://www.twilio.com).

Installation
============

Installation of Text-to-Vote is as simple as copying the folder, making it
writeable, editing the configuration file, creating the database and pointing
Twilio to the correct handlers.

1. Copy the folder to your server.

2. Make the folder writeable.

3. Edit `/include/config.php`

4. Run `create_database.php` by browsing to `http://yourserver/Text-to-Vote/create_database.php`

5. Go to your [Twilio numbers page](https://www.twilio.com/user/account/phone-numbers/)
and point the Voice URL to `http://yourserver/Text-to-Vote/handle_incoming_call.xml`
(leave the default POST method selected) and point the SMS URL to
`http://yourserver/Text-to-Vote/handle_incoming_sms.php`

License
=======

Copyright (C) 2011 Rahim Sonawalla ([[email protected]](mailto:[email protected]) / [@rahims](http://twitter.com/rahims)) and Will Light ([[email protected]](mailto:[email protected]) / [@dudestache](http://twitter.com/dudestache)).

Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
2 changes: 2 additions & 0 deletions _gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
*.swp
14 changes: 14 additions & 0 deletions create_database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once('./include/db.php');

if (file_exists('votes.sqlite') != true)
{
$db = new DB();
$db->init();

echo 'Database created.';
}
else {
echo 'Database already exists. Feel free to delete me.';
}
?>
13 changes: 13 additions & 0 deletions get_votes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
require_once('./include/db.php');

$db = new DB();
$teams = $db->get_teams();

foreach ($teams as $team)
{
$votes[] = (int) $team['votes'];
}

echo json_encode($votes);
?>
4 changes: 4 additions & 0 deletions handle_incoming_call.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Say voice="woman">Voting is powered by Twilio. Visit www.twilio.com for more information.</Say>
</Response>
22 changes: 22 additions & 0 deletions handle_incoming_sms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
require_once('./include/db.php');

header('Content-type: text/xml');
echo '<Response>';

$phone_number = $_REQUEST['From'];
$team_number = (int) $_REQUEST['Body'];

if ( (strlen($phone_number) >= 10) && ($team_number > 0) )
{
$db = new DB();

$response = $db->save_vote($phone_number, $team_number);
}
else {
$response = 'Sorry, I didn\'t understand that. Text the team number to vote. For example, texting 1 will vote for Team 1.';
}

echo '<Sms>'.$response.'</Sms>';
echo '</Response>';
?>
127 changes: 127 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
require_once('./include/db.php');

ob_start("ob_gzhandler");

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$base_url = 'http://'.$host.$uri.'/';
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<title><?php echo POLL_NAME; ?></title>

<meta http-equiv="content-type" content="text/html; charset=utf-8">

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="./js/protovis-r3.3.js"></script>

<link rel="stylesheet" type="text/css" href="./css/reset.css" media="screen">
<link rel="stylesheet" type="text/css" href="./css/main.css" media="screen">
</head>
<body>
<div id="container">
<h1>Text team number to <strong><?php echo PHONE_NUMBER ?></strong></h1>
<div id="results">
<script type="text/javascript+protovis">
<?php
$db = new DB();

$teams = $db->get_teams();

$images = json_encode($logos);

foreach ($teams as $team)
{
$data[] = (int) $team['votes'];
}

$data = json_encode($data);
?>

var images = <?php echo $images; ?>;

var data = <?php echo $data; ?>;

/* Protovis wizardy by Will Light (http://williamlight.net) */

/* Sizing and scales. */
var w = 700,
h = 400,
x = pv.Scale.linear(0, (pv.max(data) == 0 ? 1 : pv.max(data))).range(0, w),
y = pv.Scale.ordinal(pv.range(data.length)).splitBanded(0, h, 4/5);

/* The root panel. */
var vis = new pv.Panel()
.width(w)
.height(h)
.bottom(20)
.left(90)
.right(40)
.top(5);

/* The bars. */
var bar = vis.add(pv.Bar)
.data(function() data)
.top(function() y(this.index))
.height(y.range().band)
.left(60)
.width(x);

/* Y-axis label */
vis.add(pv.Label)
.data(["Team Number"])
.left(-63)
.bottom(h/2)
.font("30px Helvetica")
.textAlign("center")
.textAngle(-Math.PI/2);

/* The variable label. */
var what = bar.anchor("left")
.add(pv.Bar)
.width(function() this.root.left())
.height(y.range().band)
.top(function() y(this.index))
.fillStyle("rgba(0, 0, 0, 0)");

bar.anchor("left").add(pv.Label)
.textMargin(5)
.left(55)
.textAlign("right")
.font("bold 30px Helvetica")
.text(function() this.index + 1);

what.add(pv.Image)
.left(-40)
.top(function() y(this.index) + ((y.range().band / 2) - (this.height() / 2)))
.width(64)
.height(64)
.url(function() images[this.index]);

vis.render();
getData();

function getData() {
$.getJSON ("<?php echo $base_url.'get_votes.php'; ?>", function (d) {
data = d;
x = pv.Scale.linear(0, (pv.max(data) == 0 ? 1 : pv.max(data))).range(0, w);
bar.width(x);

vis.transition()
.duration(500)
.ease("elastic-out")
.start();
});
}

setInterval(function() { getData(); }, 2000);
</script>
</div>
<p><img src="./images/twilio_logo.png"></p>
</div>
</body>
</html>

0 comments on commit a174ec7

Please sign in to comment.