| 1 |
<?php /* $Id: page.ringgroups.php 1762 2006-04-28 19:15:31Z p_lindheimer $ */ |
|---|
| 2 |
//Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) |
|---|
| 3 |
// |
|---|
| 4 |
//This program is free software; you can redistribute it and/or |
|---|
| 5 |
//modify it under the terms of the GNU General Public License |
|---|
| 6 |
//as published by the Free Software Foundation; either version 2 |
|---|
| 7 |
//of the License, or (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
//This program is distributed in the hope that it will be useful, |
|---|
| 10 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
//GNU General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
$dispnum = 'ringgroups'; //used for switch on config.php |
|---|
| 15 |
|
|---|
| 16 |
isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action=''; |
|---|
| 17 |
//the extension we are currently displaying |
|---|
| 18 |
isset($_REQUEST['extdisplay'])?$extdisplay=$_REQUEST['extdisplay']:$extdisplay=''; |
|---|
| 19 |
isset($_REQUEST['account'])?$account = $_REQUEST['account']:$account=''; |
|---|
| 20 |
isset($_REQUEST['grptime'])?$grptime = $_REQUEST['grptime']:$grptime=''; |
|---|
| 21 |
isset($_REQUEST['grppre'])?$grppre = $_REQUEST['grppre']:$grppre=''; |
|---|
| 22 |
isset($_REQUEST['strategy'])?$strategy = $_REQUEST['strategy']:$strategy=''; |
|---|
| 23 |
isset($_REQUEST['annmsg'])?$annmsg = $_REQUEST['annmsg']:$annmsg=''; |
|---|
| 24 |
isset($_REQUEST['description'])?$description = $_REQUEST['description']:$description=''; |
|---|
| 25 |
isset($_REQUEST['alertinfo'])?$alertinfo = $_REQUEST['alertinfo']:$alertinfo=''; |
|---|
| 26 |
|
|---|
| 27 |
if (isset($_REQUEST['goto0']) && isset($_REQUEST[$_REQUEST['goto0']."0"])) { |
|---|
| 28 |
$goto = $_REQUEST[$_REQUEST['goto0']."0"]; |
|---|
| 29 |
} else { |
|---|
| 30 |
$goto = ''; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
if (isset($_REQUEST["grplist"])) { |
|---|
| 35 |
$grplist = explode("\n",$_REQUEST["grplist"]); |
|---|
| 36 |
|
|---|
| 37 |
if (!$grplist) { |
|---|
| 38 |
$grplist = null; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
foreach (array_keys($grplist) as $key) { |
|---|
| 42 |
//trim it |
|---|
| 43 |
$grplist[$key] = trim($grplist[$key]); |
|---|
| 44 |
|
|---|
| 45 |
// remove invalid chars |
|---|
| 46 |
$grplist[$key] = preg_replace("/[^0-9#*]/", "", $grplist[$key]); |
|---|
| 47 |
|
|---|
| 48 |
// remove blanks |
|---|
| 49 |
if ($grplist[$key] == "") unset($grplist[$key]); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
// check for duplicates, and re-sequence |
|---|
| 53 |
$grplist = array_values(array_unique($grplist)); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
// do if we are submitting a form |
|---|
| 57 |
if(isset($_POST['action'])){ |
|---|
| 58 |
//check if the extension is within range for this user |
|---|
| 59 |
if (isset($account) && !checkRange($account)){ |
|---|
| 60 |
echo "<script>javascript:alert('". _("Warning! Extension")." ".$account." "._("is not allowed for your account").".');</script>"; |
|---|
| 61 |
} else { |
|---|
| 62 |
//add group |
|---|
| 63 |
if ($action == 'addGRP') { |
|---|
| 64 |
//ringgroups_add($account,implode("-",$grplist),$strategy,$grptime,$grppre,$goto); |
|---|
| 65 |
ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo); |
|---|
| 66 |
needreload(); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
//del group |
|---|
| 70 |
if ($action == 'delGRP') { |
|---|
| 71 |
ringgroups_del($account); |
|---|
| 72 |
needreload(); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
//edit group - just delete and then re-add the extension |
|---|
| 76 |
if ($action == 'edtGRP') { |
|---|
| 77 |
ringgroups_del($account); |
|---|
| 78 |
ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo); |
|---|
| 79 |
needreload(); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
?> |
|---|
| 84 |
</div> |
|---|
| 85 |
|
|---|
| 86 |
<div class="rnav"> |
|---|
| 87 |
<li><a id="<?php echo ($extdisplay=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add Ring Group")?></a></li> |
|---|
| 88 |
<?php |
|---|
| 89 |
//get unique ring groups |
|---|
| 90 |
$gresults = ringgroups_list(); |
|---|
| 91 |
|
|---|
| 92 |
if (isset($gresults)) { |
|---|
| 93 |
foreach ($gresults as $gresult) { |
|---|
| 94 |
echo "<li><a id=\"".($extdisplay=='GRP-'.$gresult[0] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&extdisplay=".urlencode("GRP-".$gresult[0])."\">".$gresult[1]." ({$gresult[0]})</a></li>"; |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
?> |
|---|
| 98 |
</div> |
|---|
| 99 |
|
|---|
| 100 |
<div class="content"> |
|---|
| 101 |
<?php |
|---|
| 102 |
if ($action == 'delGRP') { |
|---|
| 103 |
echo '<br><h3>'._("Ring Group").' '.$account.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>'; |
|---|
| 104 |
} else { |
|---|
| 105 |
if ($extdisplay) { |
|---|
| 106 |
// We need to populate grplist with the existing extension list. |
|---|
| 107 |
$thisgrp = ringgroups_get(ltrim($extdisplay,'GRP-')); |
|---|
| 108 |
$grpliststr = $thisgrp['grplist']; |
|---|
| 109 |
$grplist = explode("-", $grpliststr); |
|---|
| 110 |
$strategy = $thisgrp['strategy']; |
|---|
| 111 |
$grppre = $thisgrp['grppre']; |
|---|
| 112 |
$grptime = $thisgrp['grptime']; |
|---|
| 113 |
$goto = $thisgrp['postdest']; |
|---|
| 114 |
$annmsg = $thisgrp['annmsg']; |
|---|
| 115 |
$description = $thisgrp['description']; |
|---|
| 116 |
$alertinfo = $thisgrp['alertinfo']; |
|---|
| 117 |
unset($grpliststr); |
|---|
| 118 |
unset($thisgrp); |
|---|
| 119 |
|
|---|
| 120 |
$delButton = " |
|---|
| 121 |
<form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST> |
|---|
| 122 |
<input type=\"hidden\" name=\"display\" value=\"{$dispnum}\"> |
|---|
| 123 |
<input type=\"hidden\" name=\"account\" value=\"".ltrim($extdisplay,'GRP-')."\"> |
|---|
| 124 |
<input type=\"hidden\" name=\"action\" value=\"delGRP\"> |
|---|
| 125 |
<input type=submit value=\""._("Delete Group")."\"> |
|---|
| 126 |
</form>"; |
|---|
| 127 |
|
|---|
| 128 |
echo "<h2>"._("Ring Group").": ".ltrim($extdisplay,'GRP-')."</h2>"; |
|---|
| 129 |
echo "<p>".$delButton."</p>"; |
|---|
| 130 |
} else { |
|---|
| 131 |
$grplist = explode("-", '');; |
|---|
| 132 |
$strategy = ''; |
|---|
| 133 |
$grppre = ''; |
|---|
| 134 |
$grptime = ''; |
|---|
| 135 |
$goto = ''; |
|---|
| 136 |
$annmsg = ''; |
|---|
| 137 |
$alertinfo = ''; |
|---|
| 138 |
|
|---|
| 139 |
echo "<h2>"._("Add Ring Group")."</h2>"; |
|---|
| 140 |
} |
|---|
| 141 |
?> |
|---|
| 142 |
<form name="editGRP" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkGRP(editGRP);"> |
|---|
| 143 |
<input type="hidden" name="display" value="<?php echo $dispnum?>"> |
|---|
| 144 |
<input type="hidden" name="action" value="<?php echo ($extdisplay ? 'edtGRP' : 'addGRP'); ?>"> |
|---|
| 145 |
<table> |
|---|
| 146 |
<tr><td colspan="2"><h5><?php echo ($extdisplay ? _("Edit Ring Group") : _("Add Ring Group")) ?><hr></h5></td></tr> |
|---|
| 147 |
<tr> |
|---|
| 148 |
<?php |
|---|
| 149 |
if ($extdisplay) { |
|---|
| 150 |
|
|---|
| 151 |
?> |
|---|
| 152 |
<input size="5" type="hidden" name="account" value="<?php echo ltrim($extdisplay,'GRP-'); ?>"> |
|---|
| 153 |
<?php } else { ?> |
|---|
| 154 |
<td><a href="#" class="info"><?php echo _("group number")?>:<span><?php echo _("The number users will dial to ring extensions in this ring group")?></span></a></td> |
|---|
| 155 |
<td><input size="5" type="text" name="account" value="<?php echo $gresult[0] + 1; ?>"></td> |
|---|
| 156 |
<?php } ?> |
|---|
| 157 |
</tr> |
|---|
| 158 |
<tr> |
|---|
| 159 |
<td> <a href="#" class="info"><?php echo _("group description:")?></td> |
|---|
| 160 |
<td><input size="20" maxlength="35" type="text" name="description" value="<?php echo htmlspecialchars($description); ?>"></td> |
|---|
| 161 |
</tr> |
|---|
| 162 |
<tr> |
|---|
| 163 |
<td> <a href="#" class="info"><?php echo _("ring strategy:")?> |
|---|
| 164 |
<span> |
|---|
| 165 |
<b><?php echo _("ringall")?></b>: <?php echo _("ring all available channels until one answers (default)")?><br> |
|---|
| 166 |
<b><?php echo _("hunt")?></b>: <?php echo _("take turns ringing each available extension")?><br> |
|---|
| 167 |
<b><?php echo _("memoryhunt")?></b>: <?php echo _("ring first extension in the list, then ring the 1st and 2nd extension, then ring 1st 2nd and 3rd extension in the list.... etc.")?><br> |
|---|
| 168 |
</span> |
|---|
| 169 |
</a></td> |
|---|
| 170 |
<td> |
|---|
| 171 |
<select name="strategy"/> |
|---|
| 172 |
<?php |
|---|
| 173 |
$default = (isset($strategy) ? $strategy : 'ringall'); |
|---|
| 174 |
$items = array('ringall','hunt','memoryhunt'); |
|---|
| 175 |
foreach ($items as $item) { |
|---|
| 176 |
echo '<option value="'.$item.'" '.($default == $item ? 'SELECTED' : '').'>'._($item); |
|---|
| 177 |
} |
|---|
| 178 |
?> |
|---|
| 179 |
</select> |
|---|
| 180 |
</td> |
|---|
| 181 |
</tr> |
|---|
| 182 |
<tr> |
|---|
| 183 |
<td valign="top"><a href="#" class="info"><?php echo _("extension list")?>:<span><br><?php echo _("List extensions to ring, one per line.<br><br>You can include an extension on a remote system, or an external number by suffixing a number with a pound (#). ex: 2448089# would dial 2448089 on the appropriate trunk (see Outbound Routing).")?><br><br></span></a></td> |
|---|
| 184 |
<td valign="top"> |
|---|
| 185 |
<?php |
|---|
| 186 |
$rows = count($grplist)+1; |
|---|
| 187 |
($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows); |
|---|
| 188 |
?> |
|---|
| 189 |
<textarea id="grplist" cols="15" rows="<?php echo $rows ?>" name="grplist"><?php echo implode("\n",$grplist);?></textarea><br> |
|---|
| 190 |
|
|---|
| 191 |
<input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" /> |
|---|
| 192 |
</td> |
|---|
| 193 |
</tr> |
|---|
| 194 |
<tr> |
|---|
| 195 |
<td><a href="#" class="info"><?php echo _("CID name prefix")?>:<span><?php echo _('You can optionally prefix the Caller ID name when ringing extensions in this group. ie: If you prefix with "Sales:", a call from John Doe would display as "Sales:John Doe" on the extensions that ring.')?></span></a></td> |
|---|
| 196 |
<td><input size="4" type="text" name="grppre" value="<?php echo $grppre ?>"></td> |
|---|
| 197 |
</tr> |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
<tr> |
|---|
| 201 |
<td><?php echo _("ring time (max 60 sec)")?>:</td> |
|---|
| 202 |
<td><input size="4" type="text" name="grptime" value="<?php echo $grptime?$grptime:20 ?>"></td> |
|---|
| 203 |
</tr> |
|---|
| 204 |
<?php if(function_exists('recordings_list')) { //only include if recordings is enabled?> |
|---|
| 205 |
<tr> |
|---|
| 206 |
<td><a href="#" class="info"><?php echo _("announcement:")?><span><?php echo _("Message to be played to the caller before dialing this group.<br><br>To add additional recordings please use the \"System Recordings\" MENU to the left")?></span></a></td> |
|---|
| 207 |
<td> |
|---|
| 208 |
<select name="annmsg"/> |
|---|
| 209 |
<?php |
|---|
| 210 |
$tresults = recordings_list(); |
|---|
| 211 |
$default = (isset($annmsg) ? $annmsg : ''); |
|---|
| 212 |
echo '<option value="">'._("None")."</option>"; |
|---|
| 213 |
if (isset($tresults[0])) { |
|---|
| 214 |
foreach ($tresults as $tresult) { |
|---|
| 215 |
echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n"; |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
?> |
|---|
| 219 |
</select> |
|---|
| 220 |
</td> |
|---|
| 221 |
</tr> |
|---|
| 222 |
<?php } else { ?> |
|---|
| 223 |
<tr> |
|---|
| 224 |
<td><a href="#" class="info"><?php echo _("announcement:")?><span><?php echo _("Message to be played to the caller before dialing this group.<br><br>You must install and enable the \"Systems Recordings\" Module to edit this option")?></span></a></td> |
|---|
| 225 |
<td> |
|---|
| 226 |
<?php |
|---|
| 227 |
$default = (isset($annmsg) ? $annmsg : ''); |
|---|
| 228 |
?> |
|---|
| 229 |
<input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?> |
|---|
| 230 |
</td> |
|---|
| 231 |
</tr> |
|---|
| 232 |
<?php } ?> |
|---|
| 233 |
|
|---|
| 234 |
<tr> |
|---|
| 235 |
<td><a href="#" class="info"><?php echo _("Alert Info")?><span><?php echo _('ALERT_INFO can be used for distinctive ring with SIP devices.')?></span></a>:</td> |
|---|
| 236 |
<td><input type="text" name="alertinfo" size="10" value="<?php echo ($alertinfo)?$alertinfo:'' ?>"></td> |
|---|
| 237 |
</tr> |
|---|
| 238 |
<tr><td colspan="2"><br><h5><?php echo _("Destination if no answer")?>:<hr></h5></td></tr> |
|---|
| 239 |
|
|---|
| 240 |
<?php |
|---|
| 241 |
//draw goto selects |
|---|
| 242 |
echo drawselects($goto,0); |
|---|
| 243 |
?> |
|---|
| 244 |
|
|---|
| 245 |
<tr> |
|---|
| 246 |
<td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td> |
|---|
| 247 |
|
|---|
| 248 |
</tr> |
|---|
| 249 |
</table> |
|---|
| 250 |
</form> |
|---|
| 251 |
<?php |
|---|
| 252 |
} //end if action == delGRP |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
?> |
|---|
| 256 |
<script language="javascript"> |
|---|
| 257 |
<!-- |
|---|
| 258 |
|
|---|
| 259 |
function checkGRP(theForm) { |
|---|
| 260 |
var msgInvalidGrpNum = "<?php echo _('Invalid Group Number specified'); ?>"; |
|---|
| 261 |
var msgInvalidGrpNumStartWithZero = "<?php echo _('Group numbers with more than one digit cannot begin with 0'); ?>"; |
|---|
| 262 |
var msgInvalidExtList = "<?php echo _('Please enter an extension list.'); ?>"; |
|---|
| 263 |
var msgInvalidGrpPrefix = "<?php echo _('Invalid Caller ID prefix.'); ?>"; |
|---|
| 264 |
var msgInvalidTime = "<?php echo _('Invalid time specified'); ?>"; |
|---|
| 265 |
var msgInvalidGrpTimeRange = "<?php echo _('Time must be between 1 and 60 seconds'); ?>"; |
|---|
| 266 |
var msgInvalidDescription = "<?php echo _('Please enter a valid Group Description'); ?>"; |
|---|
| 267 |
|
|---|
| 268 |
// set up the Destination stuff |
|---|
| 269 |
setDestinations(theForm, 1); |
|---|
| 270 |
|
|---|
| 271 |
// form validation |
|---|
| 272 |
defaultEmptyOK = false; |
|---|
| 273 |
if (!isInteger(theForm.account.value)) { |
|---|
| 274 |
return warnInvalid(theForm.account, msgInvalidGrpNum); |
|---|
| 275 |
} else if (theForm.account.value.indexOf('0') == 0 && theForm.account.value.length > 1) { |
|---|
| 276 |
return warnInvalid(theForm.account, msgInvalidGrpNumStartWithZero); |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
defaultEmptyOK = false; |
|---|
| 280 |
if (!isAlphanumeric(theForm.description.value)) |
|---|
| 281 |
return warnInvalid(theForm.description, msgInvalidDescription); |
|---|
| 282 |
|
|---|
| 283 |
if (isEmpty(theForm.grplist.value)) |
|---|
| 284 |
return warnInvalid(theForm.grplist, msgInvalidExtList); |
|---|
| 285 |
|
|---|
| 286 |
defaultEmptyOK = true; |
|---|
| 287 |
if (!isCallerID(theForm.grppre.value)) |
|---|
| 288 |
return warnInvalid(theForm.grppre, msgInvalidGrpPrefix); |
|---|
| 289 |
|
|---|
| 290 |
defaultEmptyOK = false; |
|---|
| 291 |
if (!isInteger(theForm.grptime.value)) { |
|---|
| 292 |
return warnInvalid(theForm.grptime, msgInvalidTime); |
|---|
| 293 |
} else { |
|---|
| 294 |
var grptimeVal = theForm.grptime.value; |
|---|
| 295 |
if (grptimeVal < 1 || grptimeVal > 60) |
|---|
| 296 |
return warnInvalid(theForm.grptime, msgInvalidGrpTimeRange); |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
if (!validateDestinations(theForm, 1, true)) |
|---|
| 300 |
return false; |
|---|
| 301 |
|
|---|
| 302 |
return true; |
|---|
| 303 |
} |
|---|
| 304 |
//--> |
|---|
| 305 |
</script> |
|---|