| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
/** |
|---|
| 4 |
* @file |
|---|
| 5 |
* Functions for the interface to the follow me settings |
|---|
| 6 |
*/ |
|---|
| 7 |
|
|---|
| 8 |
/** |
|---|
| 9 |
* Class for Fax Settings |
|---|
| 10 |
*/ |
|---|
| 11 |
class Fax { |
|---|
| 12 |
|
|---|
| 13 |
/* |
|---|
| 14 |
* rank (for prioritizing modules) |
|---|
| 15 |
*/ |
|---|
| 16 |
function rank() { |
|---|
| 17 |
|
|---|
| 18 |
$rank = 5; |
|---|
| 19 |
return $rank; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
/* |
|---|
| 23 |
* init |
|---|
| 24 |
*/ |
|---|
| 25 |
function init() { |
|---|
| 26 |
|
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
/* |
|---|
| 30 |
* Adds menu item to nav menu |
|---|
| 31 |
* |
|---|
| 32 |
* @param $args |
|---|
| 33 |
* Common arguments |
|---|
| 34 |
*/ |
|---|
| 35 |
function navMenu($args) { |
|---|
| 36 |
|
|---|
| 37 |
global $ARI_NO_LOGIN; |
|---|
| 38 |
|
|---|
| 39 |
// check logout |
|---|
| 40 |
if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) { |
|---|
| 41 |
$logout = 1; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
if ($logout!='') { |
|---|
| 45 |
$ret .= " |
|---|
| 46 |
<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Fax&f=display'>" . _("Fax") . "</a></small></small></p>"; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
return $ret; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
/* |
|---|
| 53 |
* Acts on the user settings |
|---|
| 54 |
* |
|---|
| 55 |
* @param $args |
|---|
| 56 |
* Common arguments |
|---|
| 57 |
* @param $a |
|---|
| 58 |
* action |
|---|
| 59 |
*/ |
|---|
| 60 |
function action($args) { |
|---|
| 61 |
|
|---|
| 62 |
global $STANDALONE; |
|---|
| 63 |
global $ARI_ADMIN_USERNAME; |
|---|
| 64 |
|
|---|
| 65 |
// args |
|---|
| 66 |
$m = getArgument($args,'m'); |
|---|
| 67 |
$a = getArgument($args,'a'); |
|---|
| 68 |
|
|---|
| 69 |
$lang_code = getArgument($args,'lang_code'); |
|---|
| 70 |
|
|---|
| 71 |
$fax_email = getArgument($args,'fax_email'); |
|---|
| 72 |
$fax_delay = getArgument($args,'fax_delay'); |
|---|
| 73 |
$fax_answer = getArgument($args,'fax_answer'); |
|---|
| 74 |
$directdid = getArgument($args,'directdid'); |
|---|
| 75 |
|
|---|
| 76 |
$language = new Language(); |
|---|
| 77 |
|
|---|
| 78 |
if ($a=='update') { |
|---|
| 79 |
|
|---|
| 80 |
$exten = $_SESSION['ari_user']['extension']; |
|---|
| 81 |
if ($exten!=$ARI_ADMIN_USERNAME) { |
|---|
| 82 |
|
|---|
| 83 |
if (!$STANDALONE['use']) { |
|---|
| 84 |
|
|---|
| 85 |
// check the value of the fax email |
|---|
| 86 |
if (!isset($fax_email)) { |
|---|
| 87 |
$_SESSION['ari_error'] = |
|---|
| 88 |
_("The email for fax must be set..") . "<br>"; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
// check the vlue of the fax delay |
|---|
| 92 |
if ($fax_delay < 0 || $fax_delay > 20) { |
|---|
| 93 |
$_SESSION['ari_error'] = |
|---|
| 94 |
_("The fax delay should be a value between 0 and 20.") . "<br>"; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
// check the value of the fax answer value |
|---|
| 98 |
if ($fax_answer < 0 || $fax_answer > 2) { |
|---|
| 99 |
$_SESSION['ari_error'] = |
|---|
| 100 |
_("The fax answer value is invalid, please contact your administrator.") . "<br>"; |
|---|
| 101 |
} |
|---|
| 102 |
else { |
|---|
| 103 |
if (substr($fax_answer,1,1)=='N') { |
|---|
| 104 |
$fax_val = 0; |
|---|
| 105 |
} |
|---|
| 106 |
else if (substr($fax_answer,1,1)=='Z') { |
|---|
| 107 |
$fax_val = 1; |
|---|
| 108 |
} |
|---|
| 109 |
else { |
|---|
| 110 |
$fax_val = 2; |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
$result = $this->setFax($exten,$fax_email,$fax_delay,$fax_val,$directdid); |
|---|
| 115 |
|
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
// redirect to see updated page |
|---|
| 121 |
$ret .= " |
|---|
| 122 |
<head> |
|---|
| 123 |
<script> |
|---|
| 124 |
<!-- |
|---|
| 125 |
window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\" |
|---|
| 126 |
// --> |
|---|
| 127 |
</script> |
|---|
| 128 |
</head>"; |
|---|
| 129 |
|
|---|
| 130 |
return $ret; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
/* |
|---|
| 134 |
* Displays stats page |
|---|
| 135 |
* |
|---|
| 136 |
* @param $args |
|---|
| 137 |
* Common arguments |
|---|
| 138 |
*/ |
|---|
| 139 |
function display($args) { |
|---|
| 140 |
|
|---|
| 141 |
global $AMPORTAL_CONF_FILE; |
|---|
| 142 |
global $ASTERISKMGR_DBHOST; |
|---|
| 143 |
|
|---|
| 144 |
global $STANDALONE; |
|---|
| 145 |
global $ARI_ADMIN_USERNAME; |
|---|
| 146 |
|
|---|
| 147 |
global $loaded_modules; |
|---|
| 148 |
|
|---|
| 149 |
// args |
|---|
| 150 |
$m = getArgument($args,'m'); |
|---|
| 151 |
$q = getArgument($args,'q'); |
|---|
| 152 |
$start = getArgument($args,'start'); |
|---|
| 153 |
$span = getArgument($args,'span'); |
|---|
| 154 |
|
|---|
| 155 |
$displayname = $_SESSION['ari_user']['displayname']; |
|---|
| 156 |
$exten = $_SESSION['ari_user']['extension']; |
|---|
| 157 |
|
|---|
| 158 |
$language = new Language(); |
|---|
| 159 |
$display = new DisplaySearch(); |
|---|
| 160 |
|
|---|
| 161 |
// lang setting options |
|---|
| 162 |
if (extension_loaded('gettext')) { |
|---|
| 163 |
$setLangText = " |
|---|
| 164 |
<p class='lang'> |
|---|
| 165 |
" . _("Language:") . " |
|---|
| 166 |
" . $language->GetForm() . " |
|---|
| 167 |
</p>"; |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
// build controls |
|---|
| 171 |
if ($exten!=$ARI_ADMIN_USERNAME) { |
|---|
| 172 |
|
|---|
| 173 |
// Fax settings |
|---|
| 174 |
if (!$STANDALONE['use']) { |
|---|
| 175 |
|
|---|
| 176 |
if (isset($_SESSION['dbh_asterisk'])) { |
|---|
| 177 |
$sql = "SELECT * FROM users WHERE extension = '" . $exten . "'"; |
|---|
| 178 |
$user_db = $_SESSION['dbh_asterisk']->setFetchMode(DB_FETCHMODE_ASSOC); |
|---|
| 179 |
$user_db = $_SESSION['dbh_asterisk']->getAll($sql); |
|---|
| 180 |
if(DB::IsError($user_db)) { |
|---|
| 181 |
$_SESSION['ari_error'] = $user_db->getMessage(); |
|---|
| 182 |
} |
|---|
| 183 |
} |
|---|
| 184 |
if ($user_db[0]['answer']==0) { |
|---|
| 185 |
$_SESSION['ari_error'] = "Fax detection is not configured for your extension.<br>Contact your administrator to enable fax on your extension."; |
|---|
| 186 |
} |
|---|
| 187 |
$faxanswer_options = array('None','Zaptel','NVFax-SIP'); |
|---|
| 188 |
$fax_email = $user_db[0]['faxemail']; |
|---|
| 189 |
$fax_delay = $user_db[0]['wait']; |
|---|
| 190 |
$fax_answer = $user_db[0]['answer']; |
|---|
| 191 |
$directdid = $user_db[0]['directdid']; |
|---|
| 192 |
$fax_answer = $faxanswer_options[$fax_answer]; |
|---|
| 193 |
|
|---|
| 194 |
$set_fax_text = " |
|---|
| 195 |
<table class='fax'> |
|---|
| 196 |
<tr> |
|---|
| 197 |
<td><h3>" . _("Fax Configuration") . "</h3></td> |
|---|
| 198 |
</tr> |
|---|
| 199 |
<tr> |
|---|
| 200 |
<td>" . _("Fax email:") . "</td> |
|---|
| 201 |
<td> |
|---|
| 202 |
<input " . $faxemail_text_box_options . " name='fax_email' type='text' size=36 value='" . $fax_email . "'> |
|---|
| 203 |
</td> |
|---|
| 204 |
</tr> |
|---|
| 205 |
<tr> |
|---|
| 206 |
<td>" . _("Fax answer delay:") . "</td> |
|---|
| 207 |
<td> |
|---|
| 208 |
<input " . $faxemail_text_box_options . " name='fax_delay' type='text' size=2 value='" . $fax_delay. "'> |
|---|
| 209 |
</td> |
|---|
| 210 |
</tr>"; |
|---|
| 211 |
/* |
|---|
| 212 |
<tr> |
|---|
| 213 |
<td>" . _("Fax Receive Method:") . "</td> |
|---|
| 214 |
<td> |
|---|
| 215 |
<select name='fax_answer'>"; |
|---|
| 216 |
// Add the fax receiving options |
|---|
| 217 |
foreach ($faxanswer_options as $opts) |
|---|
| 218 |
if ($fax_answer == $opts) { |
|---|
| 219 |
$set_fax_text .= "<option selected value='" . $opts . "'>" . $opts . "</option>"; |
|---|
| 220 |
} |
|---|
| 221 |
else { |
|---|
| 222 |
$set_fax_text .= "<option value='" . $opts . "'>" . $opts . "</option>"; |
|---|
| 223 |
} |
|---|
| 224 |
$set_fax_text .= " |
|---|
| 225 |
</select> |
|---|
| 226 |
</td> |
|---|
| 227 |
</tr> |
|---|
| 228 |
*/ |
|---|
| 229 |
$set_fax_text .= " |
|---|
| 230 |
</table>"; |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
// build page content |
|---|
| 236 |
$ret .= checkErrorMessage(); |
|---|
| 237 |
|
|---|
| 238 |
if ($_SESSION['ari_user']['admin_settings']) { |
|---|
| 239 |
$headerText = _("Fax"); |
|---|
| 240 |
} else { |
|---|
| 241 |
$headerText = sprintf(_("Fax Settings for %s (%s)"),$displayname,$exten); |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
if ($user_db[0]['answer']==0) { |
|---|
| 245 |
$set_fax_text = ''; |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
$ret .= $display->displayHeaderText($headerText); |
|---|
| 249 |
$ret .= $display->displayLine(); |
|---|
| 250 |
|
|---|
| 251 |
$ret .= " |
|---|
| 252 |
" . $setLangText . " |
|---|
| 253 |
<form class='settings' name='ari_settings' action='' method='GET'> |
|---|
| 254 |
<input type=hidden name=m value=" . $m . "> |
|---|
| 255 |
<input type=hidden name=f value='action'> |
|---|
| 256 |
<input type=hidden name=a value='update'> |
|---|
| 257 |
<input type=hidden name='directdid' value='" . $directdid . "'> |
|---|
| 258 |
<br> |
|---|
| 259 |
" . $set_fax_text . " |
|---|
| 260 |
<br> |
|---|
| 261 |
<input name='submit' type='submit' value='" . _("Update") . "'> |
|---|
| 262 |
</form>"; |
|---|
| 263 |
|
|---|
| 264 |
return $ret; |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
/* |
|---|
| 268 |
* Sets all fax values |
|---|
| 269 |
* |
|---|
| 270 |
* @param $exten |
|---|
| 271 |
* Extension to modify |
|---|
| 272 |
* @param $fax_email |
|---|
| 273 |
* Email for faxes |
|---|
| 274 |
* @param $fax_delay |
|---|
| 275 |
* Delay to wait for fax tones |
|---|
| 276 |
* @param $fax_answer |
|---|
| 277 |
* Type of fax detection |
|---|
| 278 |
* @param $directdid |
|---|
| 279 |
* Any value of direct did for the extension |
|---|
| 280 |
*/ |
|---|
| 281 |
function setFax($exten,$fax_email,$fax_delay,$fax_answer,$directdid) { |
|---|
| 282 |
|
|---|
| 283 |
global $asterisk_manager_interface; |
|---|
| 284 |
|
|---|
| 285 |
// Update the mysql tables |
|---|
| 286 |
if (isset($_SESSION['dbh_asterisk'])) { |
|---|
| 287 |
$sql = "UPDATE users SET faxemail='" . $fax_email; |
|---|
| 288 |
$sql .= "', wait=" . $fax_delay; |
|---|
| 289 |
$sql .= " WHERE extension='" . $exten . "'"; |
|---|
| 290 |
$results = $_SESSION['dbh_asterisk']->getAll($sql); |
|---|
| 291 |
if(DB::IsError($results)) { |
|---|
| 292 |
$_SESSION['ari_error'] = $results->getMessage(); |
|---|
| 293 |
} |
|---|
| 294 |
} |
|---|
| 295 |
// Retrieve the values for the DID on the extension |
|---|
| 296 |
if (isset($_SESSION['dbh_asterisk'])) { |
|---|
| 297 |
$sql = "SELECT directdid FROM users "; |
|---|
| 298 |
$sql .= " WHERE extension='" . $exten . "'"; |
|---|
| 299 |
$results = $_SESSION['dbh_asterisk']->getAll($sql); |
|---|
| 300 |
if(DB::IsError($results)) { |
|---|
| 301 |
$_SESSION['ari_error'] = $results->getMessage(); |
|---|
| 302 |
} |
|---|
| 303 |
$directdid = $results[0][0]; |
|---|
| 304 |
} |
|---|
| 305 |
// Update the AstDB for this extension and DID |
|---|
| 306 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/faxrxemail\r\n\r\n"); |
|---|
| 307 |
if (!strstr('not found',$response)) { |
|---|
| 308 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/faxrxemail $fax_email\r\n\r\n"); |
|---|
| 309 |
} |
|---|
| 310 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $directdid/faxrxemail\r\n\r\n"); |
|---|
| 311 |
if (!strstr('not found',$response)) { |
|---|
| 312 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $directdid/faxrxemail $fax_email\r\n\r\n"); |
|---|
| 313 |
} |
|---|
| 314 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/nvfaxdetect\r\n\r\n"); |
|---|
| 315 |
if (!strstr('not found',$response)) { |
|---|
| 316 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/nvfaxdetect $fax_delay\r\n\r\n"); |
|---|
| 317 |
} |
|---|
| 318 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $directdid/nvfaxdetect\r\n\r\n"); |
|---|
| 319 |
if (!strstr('not found',$response)) { |
|---|
| 320 |
$response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $directdid/nvfaxdetect $fax_delay\r\n\r\n"); |
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
return $response; |
|---|
| 325 |
|
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
?> |
|---|