Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix PHP notices

  • Loading branch information...
commit a95a12fee870dde84a06ae0f9bf09fbbd206e127 1 parent 4d746c0
@chadsmith authored
Showing with 80 additions and 74 deletions.
  1. +11 −8 applets/poll/twiml.php
  2. +19 −19 polls.js
  3. +50 −47 polls.php
View
19 applets/poll/twiml.php
@@ -2,15 +2,18 @@
$ci =& get_instance();
$poll = AppletInstance::getValue('poll');
$option = AppletInstance::getValue('option');
-$number = normalize_phone_to_E164($_REQUEST['From']);
-$ci->db->delete('polls_responses', array('poll' => $poll, 'value' => $number));
-$ci->db->insert('polls_responses', array(
- 'poll' => $poll,
- 'value' => $number,
- 'response' => $option,
- 'time' => time()
-));
+if(!empty($_REQUEST['From'])) {
+ $number = normalize_phone_to_E164($_REQUEST['From']);
+
+ $ci->db->delete('polls_responses', array('poll' => $poll, 'value' => $number));
+ $ci->db->insert('polls_responses', array(
+ 'poll' => $poll,
+ 'value' => $number,
+ 'response' => $option,
+ 'time' => time()
+ ));
+}
$response = new Response();
View
38 polls.js
@@ -1,34 +1,34 @@
$(function(){
$('#button-add-poll').click(function(e) {
- $('.vbx-polls form:not(:first):visible,.vbx-polls .option').slideUp();
+ $('.vbx-polls form:not(:first):visible, .vbx-polls .option').slideUp();
$('.vbx-polls form:first').slideToggle();
return false;
});
- $('.vbx-polls form button').eq(0).click(function(){
- var $label=$('label.option');
+ $('.vbx-polls form button').eq(0).click(function() {
+ var $label = $('label.option');
$label.last().after($('<div>').append($label.first().clone()).html());
return false;
});
- $('.vbx-polls a.options').click(function(){
- var $poll=$(this).parent().parent().parent();
- var id=$poll.attr('id');
- $('.vbx-polls .option:not(.'+id+'):visible,.vbx-polls form').slideUp();
- $('.vbx-polls .option.'+id).slideToggle();
+ $('.vbx-polls a.options').click(function() {
+ var $poll = $(this).parent().parent().parent();
+ var id = $poll.attr('id');
+ $('.vbx-polls .option:not(.' + id + '):visible, .vbx-polls form').slideUp();
+ $('.vbx-polls .option.' + id).slideToggle();
return false;
});
- $('.vbx-polls .poll a.delete').click(function(){
- var $poll=$(this).parent().parent().parent();
- var id=$poll.attr('id');
- if(confirm('You are about to delete "'+$poll.children().children('span').eq(0).text()+'" and all its responses.'))
+ $('.vbx-polls .poll a.delete').click(function() {
+ var $poll = $(this).parent().parent().parent();
+ var id = $poll.attr('id');
+ if(confirm('You are about to delete "' + $poll.children().children('span').eq(0).text() + '" and all its responses.'))
$.ajax({
- type:'POST',
- url:window.location,
- data:{remove:id.match(/([\d]+)/)[1]},
- success:function(){
- $poll.add('.vbx-polls .option.'+id).hide(500);
+ type: 'POST',
+ url: window.location,
+ data: { remove: id.match(/([\d]+)/)[1] },
+ success: function() {
+ $poll.add('.vbx-polls .option.' + id).hide(500);
},
- dataType:'text'
+ dataType: 'text'
});
return false
});
-})
+})
View
97 polls.php
@@ -2,21 +2,24 @@
$user = OpenVBX::getCurrentUser();
$tenant_id = $user->values['tenant_id'];
$ci =& get_instance();
- $queries = explode(';', file_get_contents(dirname(__FILE__).'/db.sql'));
+ $queries = explode(';', file_get_contents(dirname(__FILE__) . '/db.sql'));
foreach($queries as $query)
if(trim($query))
$ci->db->query($query);
- if($remove = intval($_POST['remove'])){
+ if(!empty($_POST['remove'])) {
+ $remove = intval($_POST['remove']);
$ci->db->delete('polls', array('id' => $remove, 'tenant' => $tenant_id));
if($ci->db->affected_rows())
$ci->db->delete('polls_responses', array('poll' => $remove));
- die();
+ die;
}
- if($poll = intval($_REQUEST['poll'])){
- echo $ci->db->query(sprintf('SELECT data FROM polls WHERE tenant=%d AND id=%d', $tenant_id, $poll))->row()->data;
- die();
+ if(!empty($_REQUEST['poll'])) {
+ echo $ci->db->query(sprintf('SELECT data FROM polls WHERE tenant = %d AND id = %d', $tenant_id, intval($_REQUEST['poll'])))->row()->data;
+ die;
}
- if(($name = htmlentities($_POST['name']))&&($options = $_POST['option'])&&is_array($options)){
+ if(!empty($_POST['name']) && 1 < count($_POST['option'])) {
+ $name = htmlentities($_POST['name']);
+ $options = $_POST['option'];
foreach($options as &$option)
$option = htmlentities($option);
$ci->db->insert('polls', array(
@@ -25,61 +28,61 @@
'data' => json_encode($options)
));
}
- $polls = $ci->db->query(sprintf('SELECT id, name, data, (SELECT COUNT(id) FROM polls_responses WHERE polls_responses.poll=polls.id) AS responses FROM polls WHERE tenant=%d', $tenant_id))->result();
+ $polls = $ci->db->query(sprintf('SELECT id, name, data, (SELECT COUNT(id) FROM polls_responses WHERE polls_responses.poll = polls.id) AS responses FROM polls WHERE tenant = %d', $tenant_id))->result();
OpenVBX::addJS('polls.js');
?>
<style>
.vbx-polls h3 {
- font-size:16px;
- font-weight:bold;
- margin-top:0;
+ font-size: 16px;
+ font-weight: bold;
+ margin-top: 0;
}
.vbx-polls .poll,
.vbx-polls div.option {
- clear:both;
- width:95%;
- overflow:hidden;
- margin:0 auto;
- padding:5px 0;
- border-bottom:1px solid #eee;
- list-style:disc;
+ clear: both;
+ width: 95%;
+ overflow: hidden;
+ margin: 0 auto;
+ padding: 5px 0;
+ border-bottom: 1px solid #eee;
+ list-style: disc;
}
.vbx-polls div.option {
- display:none;
- background:#ccc;
+ display: none;
+ background: #ccc;
}
.vbx-polls .poll span {
- display:inline-block;
- width:25%;
- text-align:center;
- float:left;
- vertical-align:middle;
- line-height:24px;
+ display: inline-block;
+ width: 25%;
+ text-align: center;
+ float: left;
+ vertical-align: middle;
+ line-height: 24px;
}
.vbx-polls .option span {
- display:inline-block;
- width:25%;
- text-align:center;
- float:left;
- vertical-align:middle;
- line-height:24px;
+ display: inline-block;
+ width: 25%;
+ text-align: center;
+ float: left;
+ vertical-align: middle;
+ line-height: 24px;
}
.vbx-polls .poll a {
- text-decoration:none;
- color:#111;
+ text-decoration: none;
+ color: #111;
}
.vbx-polls form {
- display:none;
- padding:20px 5%;
- background:#eee;
- border-bottom:1px solid #ccc;
+ display: none;
+ padding: 20px 5%;
+ background: #eee;
+ border-bottom: 1px solid #ccc;
}
.vbx-polls a.delete {
- display:inline-block;
- height:24px;
- width:24px;
- text-indent:-999em;
- background:transparent url(/assets/i/action-icons-sprite.png) no-repeat -68px 0;
+ display: inline-block;
+ height: 24px;
+ width: 24px;
+ text-indent: -999em;
+ background: transparent url(/assets/i/action-icons-sprite.png) no-repeat -68px 0;
}
</style>
<div class="vbx-content-main">
@@ -88,7 +91,7 @@
<ul class="vbx-menu-items-right">
<li class="menu-item"><button id="button-add-poll" class="inline-button add-button"><span>Add Poll</span></button></li>
</ul>
- </div><!-- .vbx-content-menu -->
+ </div>
<div class="vbx-table-section vbx-polls">
<form method="post" action="">
<h3>Add Poll</h3>
@@ -116,7 +119,7 @@
</div>
<?php foreach($polls as $poll):
$options = json_decode($poll->data);
- $responses = $ci->db->query(sprintf('SELECT COUNT(id) AS num FROM polls_responses WHERE polls_responses.poll=%d GROUP BY response ORDER BY response', $poll->id))->result(); ?>
+ $responses = $ci->db->query(sprintf('SELECT COUNT(id) AS num FROM polls_responses WHERE polls_responses.poll = %d GROUP BY response ORDER BY response', $poll->id))->result(); ?>
<div class="poll" id="poll_<?php echo $poll->id; ?>">
<p>
<span><?php echo $poll->name; ?></span>
@@ -130,7 +133,7 @@
<p>
<span><?php echo $option; ?></span>
<span>&nbsp;</span>
- <span><?php echo $ci->db->query(sprintf('SELECT COUNT(id) AS num FROM polls_responses WHERE poll=%d AND response=%d', $poll->id, $i))->row()->num; ?></span>
+ <span><?php echo $ci->db->query(sprintf('SELECT COUNT(id) AS num FROM polls_responses WHERE poll = %d AND response = %d', $poll->id, $i))->row()->num; ?></span>
<span>&nbsp;</span>
</p>
</div>
@@ -138,4 +141,4 @@
<?php endforeach; ?>
<?php endif; ?>
</div>
-</div>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.