| 1 |
<?php |
|---|
| 2 |
/* $Id$ */ |
|---|
| 3 |
// |
|---|
| 4 |
/* |
|---|
| 5 |
* page.tweet2call.php |
|---|
| 6 |
* |
|---|
| 7 |
* Copyright 2009 James Finstrom <jfinstrom@RhinoEquipment.com> |
|---|
| 8 |
* |
|---|
| 9 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 10 |
* it under the terms of the GNU General Public License as published by |
|---|
| 11 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 |
* (at your option) any later version. |
|---|
| 13 |
* |
|---|
| 14 |
* This program is distributed in the hope that it will be useful, |
|---|
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 |
* GNU General Public License for more details. |
|---|
| 18 |
* |
|---|
| 19 |
* You should have received a copy of the GNU General Public License |
|---|
| 20 |
* along with this program; if not, write to the Free Software |
|---|
| 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 22 |
* MA 02110-1301, USA. |
|---|
| 23 |
*/ |
|---|
| 24 |
$tabindex = 0; |
|---|
| 25 |
isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action=''; |
|---|
| 26 |
isset($_REQUEST['id'])?$extdisplay = $_REQUEST['id']:$extdisplay=''; |
|---|
| 27 |
$dispnum = 'tweet2call'; |
|---|
| 28 |
$display='tweet2call'; |
|---|
| 29 |
$type = 'setup'; |
|---|
| 30 |
?> |
|---|
| 31 |
</div> <!-- end content div --> |
|---|
| 32 |
|
|---|
| 33 |
<script |
|---|
| 34 |
type="text/javascript" |
|---|
| 35 |
src="../../jquery-1.1.3.1.js"> |
|---|
| 36 |
</script> |
|---|
| 37 |
<script type="text/javascript"> |
|---|
| 38 |
$(function(){ |
|---|
| 39 |
// start a counter for new row IDs |
|---|
| 40 |
// by setting it to the number |
|---|
| 41 |
// of existing rows |
|---|
| 42 |
var newRowNum = 0; |
|---|
| 43 |
|
|---|
| 44 |
// bind a click event to the "Add" link |
|---|
| 45 |
$('#addnew').click(function(){ |
|---|
| 46 |
// increment the counter |
|---|
| 47 |
newRowNum += 1; |
|---|
| 48 |
|
|---|
| 49 |
// get the entire "Add" row -- |
|---|
| 50 |
// "this" refers to the clicked element |
|---|
| 51 |
// and "parent" moves the selection up |
|---|
| 52 |
// to the parent node in the DOM |
|---|
| 53 |
var addRow = $(this).parent().parent(); |
|---|
| 54 |
|
|---|
| 55 |
// copy the entire row from the DOM |
|---|
| 56 |
// with "clone" |
|---|
| 57 |
var newRow = addRow.clone(); |
|---|
| 58 |
|
|---|
| 59 |
// set the values of the inputs |
|---|
| 60 |
// in the "Add" row to empty strings |
|---|
| 61 |
$('input', addRow).val(''); |
|---|
| 62 |
|
|---|
| 63 |
// replace the HTML for the "Add" link |
|---|
| 64 |
// with the new row number |
|---|
| 65 |
$('td:first-child', newRow).html(newRowNum); |
|---|
| 66 |
|
|---|
| 67 |
// insert a remove link in the last cell |
|---|
| 68 |
$('td:last-child', newRow).html('<a href="" class="remove">Remove<\/a>'); |
|---|
| 69 |
|
|---|
| 70 |
// loop through the inputs in the new row |
|---|
| 71 |
// and update the ID and name attributes |
|---|
| 72 |
$('input', newRow).each(function(i){ |
|---|
| 73 |
var newID = newRowNum; |
|---|
| 74 |
$(this).attr('id',this.id).attr('name',this.name); |
|---|
| 75 |
|
|---|
| 76 |
}); |
|---|
| 77 |
|
|---|
| 78 |
// insert the new row into the table |
|---|
| 79 |
// "before" the Add row |
|---|
| 80 |
addRow.before(newRow); |
|---|
| 81 |
|
|---|
| 82 |
// add the remove function to the new row |
|---|
| 83 |
$('a.remove', newRow).click(function(){ |
|---|
| 84 |
$(this).parent().parent().remove(); |
|---|
| 85 |
return false; |
|---|
| 86 |
}); |
|---|
| 87 |
|
|---|
| 88 |
// prevent the default click |
|---|
| 89 |
return false; |
|---|
| 90 |
}); |
|---|
| 91 |
}); |
|---|
| 92 |
</script> |
|---|
| 93 |
|
|---|
| 94 |
<div class="content"> |
|---|
| 95 |
<?php |
|---|
| 96 |
global $dispnum; |
|---|
| 97 |
switch ($action) { |
|---|
| 98 |
case "add": |
|---|
| 99 |
break; |
|---|
| 100 |
case "delete": |
|---|
| 101 |
break; |
|---|
| 102 |
case "update": |
|---|
| 103 |
if(isset($_POST['twuser']) && isset($_POST['twpass'])){ |
|---|
| 104 |
tweet2call_add_settings($_POST['twuser'], $_POST['twpass'], $_POST['poll'], $_POST['blacklist'], $_POST['trunk']); |
|---|
| 105 |
} |
|---|
| 106 |
if(isset($_POST['del'])){ |
|---|
| 107 |
|
|---|
| 108 |
foreach($_POST['del'] as $dept ){ |
|---|
| 109 |
tweet2call_del_department($dept); |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
if(!empty($_POST['dept']) && !empty($_POST['queue']) && !empty($_POST['weight'])){ |
|---|
| 114 |
|
|---|
| 115 |
foreach(array_keys($_POST['dept']) as $n){ |
|---|
| 116 |
|
|---|
| 117 |
$dept = strtolower($_POST['dept'][$n]); |
|---|
| 118 |
$queue = $_POST['queue'][$n]; |
|---|
| 119 |
$weight = $_POST['weight'][$n]; |
|---|
| 120 |
if( $dept != ""){ |
|---|
| 121 |
tweet2call_add_department($dept, $queue, $weight); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
} |
|---|
| 126 |
break; |
|---|
| 127 |
} |
|---|
| 128 |
if (!empty($_POST['poll'])){ |
|---|
| 129 |
function croncheck($var){ |
|---|
| 130 |
if(preg_match('/tweet2call/', $var)){ |
|---|
| 131 |
return FALSE; |
|---|
| 132 |
}else{ return TRUE;} |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
exec('crontab -l', $crons); |
|---|
| 136 |
$cronfile = '*/'.$_POST['poll'].' * * * * /var/lib/asterisk/bin/tweet2call.php'." \n"; |
|---|
| 137 |
foreach(array_filter($crons, croncheck) as $cron){ |
|---|
| 138 |
$cronfile .= $cron . "\n"; |
|---|
| 139 |
} |
|---|
| 140 |
file_put_contents('/tmp/cronjobs', $cronfile); |
|---|
| 141 |
exec('crontab /tmp/cronjobs'); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
$results = sql("SELECT `extension`, `descr` FROM `queues_config`;","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 145 |
if (!empty($results)) { |
|---|
| 146 |
$queueselect = ''; |
|---|
| 147 |
foreach ($results as $result) { |
|---|
| 148 |
$queueselect .= '<option value ="'. $result[extension].'">'. $result[descr].'</option>'; |
|---|
| 149 |
} |
|---|
| 150 |
} |
|---|
| 151 |
$results = sql("SELECT * FROM `tweet2call_settings` LIMIT 1;","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 152 |
if (!empty($results)) { |
|---|
| 153 |
extract($results[0], EXTR_PREFIX_ALL, "current"); |
|---|
| 154 |
|
|---|
| 155 |
//Array ( [twitid] => Piggy_phone [twitpass] => passwordizzle [polltime] => 1 [blacklist] => 911|411|011|900 [trunk] => ZAP/g0 [lasttweet] => ) |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
?> |
|---|
| 159 |
|
|---|
| 160 |
<h2 id='title'><?php echo _("Tweet 2 Call") ?></h2></td> |
|---|
| 161 |
<br/></br><hr> |
|---|
| 162 |
<h3>Settings</h3> |
|---|
| 163 |
<form autocomplete="off" name="edit" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> |
|---|
| 164 |
<input type="hidden" name="display" value="<?php echo $display?>"> |
|---|
| 165 |
<input type="hidden" name="type" value="<?php echo $type?>"> |
|---|
| 166 |
|
|---|
| 167 |
<a href="#" class="info"><?php echo _("Twitter Username: ")?><span><?php echo _("Enter your username from twitter.com");?></span></a> <input type='text' name='twuser' value="<?php echo $current_twitid; ?>"><br/> |
|---|
| 168 |
<a href="#" class="info"><?php echo _("Twitter Password: ")?><span><?php echo _("Enter your twitter.com password");?></span></a> <input type='password' name='twpass' value="<?php echo $current_twitpass; ?>"><br/> |
|---|
| 169 |
|
|---|
| 170 |
<a href="#" class="info"><?php echo _("Outbund Trunk: ")?><span><?php echo _("The Trunk outbound calls will be made on.");?></span></a> <select name = 'trunk'> |
|---|
| 171 |
<?php |
|---|
| 172 |
$tresults = core_trunks_list(); |
|---|
| 173 |
//var_dump($tresults); |
|---|
| 174 |
foreach ($tresults as $tresult) { |
|---|
| 175 |
if ($tresilt[1] == $current_trunk ){ |
|---|
| 176 |
print('<option value="'.$tresult[1].'" SELECTED>'.$tresult[1].'</option>'); |
|---|
| 177 |
}else{ |
|---|
| 178 |
print('<option value="'.$tresult[1].'">'.$tresult[1].'</option>'); |
|---|
| 179 |
|
|---|
| 180 |
} |
|---|
| 181 |
} |
|---|
| 182 |
?> |
|---|
| 183 |
</select><br/> |
|---|
| 184 |
<a href="#" class="info"><?php echo _("Blacklist: ")?><span><?php echo _("A | deliminated list of prefixes you dont want auto dilaed 011 international, 911, 411, 900 etc. ");?></span></a> <input type='text' name='blacklist' value="<?php echo $current_blacklist; ?>"><br/> |
|---|
| 185 |
<a href="#" class="info"><?php echo _("Poll Time: ")?><span><?php echo _("How often we should check for new dm's in minutes. API Max is 100/hr per account");?></span></a> <input type='text' name='poll' value = "<?php echo $current_polltime; ?>"> (/min)<br/> |
|---|
| 186 |
<a href="#" class="info"><?php echo _("Departments:")?><span><?php echo _("The department people will be requesting, the queue outbound calls will drop to for the given department and the weight or priority given to that call (lets it cut in line)");?></span></a><br/> |
|---|
| 187 |
|
|---|
| 188 |
<?php |
|---|
| 189 |
$results = sql("SELECT * FROM `tweet2call_departments`;","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 190 |
if (empty($results)) { |
|---|
| 191 |
echo "No Current Departments"; |
|---|
| 192 |
} else { |
|---|
| 193 |
print <<<HERE |
|---|
| 194 |
<table id="tabdata0"> |
|---|
| 195 |
<thead> |
|---|
| 196 |
<tr> |
|---|
| 197 |
<th><a href="#" class="info"><?php echo _("DEL")?><span><?php echo _("Check the box to delete the entry");?></span></a></th><th>Department</th><th>Queue</th><th>Weight</th> |
|---|
| 198 |
</tr></thead><tbody> |
|---|
| 199 |
HERE; |
|---|
| 200 |
foreach ($results as $result) { |
|---|
| 201 |
echo '<tr> |
|---|
| 202 |
<td><input type="checkbox" name = "del[]" value = "'.$result['department'].'"></td> |
|---|
| 203 |
<td>'.$result['department'].'</td> |
|---|
| 204 |
<td>'.$result['queue'].'</td> |
|---|
| 205 |
<td>'.$result['weight'].'</td> |
|---|
| 206 |
</tr>'; |
|---|
| 207 |
} |
|---|
| 208 |
print("</tbody></table><br><br>"); |
|---|
| 209 |
} |
|---|
| 210 |
?> |
|---|
| 211 |
|
|---|
| 212 |
<table id="tabdata"> |
|---|
| 213 |
<thead> |
|---|
| 214 |
<tr> |
|---|
| 215 |
<th>Row</th> |
|---|
| 216 |
<th>Department</th> |
|---|
| 217 |
<th>Queue</th> |
|---|
| 218 |
<th>Weight</th> |
|---|
| 219 |
|
|---|
| 220 |
<th></th> |
|---|
| 221 |
</tr> |
|---|
| 222 |
</thead> |
|---|
| 223 |
<tbody> |
|---|
| 224 |
<tr> |
|---|
| 225 |
<td><a id="addnew" href="">Add</a></td> |
|---|
| 226 |
<td><input id="dept" name="dept[]" type="text" /></td> |
|---|
| 227 |
<!-- <td><input id="queue" name="queue[]" type="text" /></td> --> |
|---|
| 228 |
<td><select id='queue' name='queue[]'><?php echo $queueselect; ?></select></td> |
|---|
| 229 |
<td><input id="weight" name="weight[]" type="text" size="4" /></td> |
|---|
| 230 |
<td></td> |
|---|
| 231 |
</tr> |
|---|
| 232 |
</tbody> |
|---|
| 233 |
</table> |
|---|
| 234 |
|
|---|
| 235 |
<input type="hidden" name="action" value="update"> |
|---|
| 236 |
<input type='submit'> |
|---|
| 237 |
|
|---|
| 238 |
</form> |
|---|
| 239 |
</body> |
|---|
| 240 |
</html> |
|---|