| 1 |
<? |
|---|
| 2 |
|
|---|
| 3 |
Function agentadministration_reformatnameentry($nameentry,$returntype) { |
|---|
| 4 |
|
|---|
| 5 |
//This function returns a reformatted entry for the dropdown |
|---|
| 6 |
|
|---|
| 7 |
$newstr=substr($nameentry,9); //Chop off the "agent =>" part. |
|---|
| 8 |
|
|---|
| 9 |
$data=explode(",",$newstr); //Put in array |
|---|
| 10 |
|
|---|
| 11 |
/* |
|---|
| 12 |
|
|---|
| 13 |
$data[0] - The Agent ID |
|---|
| 14 |
$data[1] - The Agent password |
|---|
| 15 |
$data[2] - The Agent name |
|---|
| 16 |
|
|---|
| 17 |
*/ |
|---|
| 18 |
|
|---|
| 19 |
if ($returntype==0) { //If returntype=0, return full entry ((Agent ID, Agent name and Agent password) |
|---|
| 20 |
|
|---|
| 21 |
$newnameentry=trim($data[0]).":".trim($data[2])."::".trim($data[1]); |
|---|
| 22 |
return $newnameentry; |
|---|
| 23 |
|
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
else return trim($data[0]); //If returntype=1, return just Agent ID. |
|---|
| 27 |
|
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
Function agentadministration_searchreplacewithinfile($Filename,$Searchstring,$Replacestring) { |
|---|
| 32 |
|
|---|
| 33 |
//This function provides a serach and replace within the file. It uses a temp file to create the new file and then renames that. |
|---|
| 34 |
|
|---|
| 35 |
$f_read=fopen("/etc/asterisk/".$Filename,"r"); //Read the original agents.conf file |
|---|
| 36 |
$f_write=fopen("/etc/asterisk/mytemp.conf","w+"); //For writing to the temp file |
|---|
| 37 |
$rewriteflag=0; //If we are rewriting. Set to off. |
|---|
| 38 |
|
|---|
| 39 |
while ($line=fgets($f_read,9000) ) { |
|---|
| 40 |
|
|---|
| 41 |
//Compare the searchstring with the text |
|---|
| 42 |
if (strcmp(trim($Searchstring),trim($line))==0) { //A match is found. Also case sensitive. |
|---|
| 43 |
|
|---|
| 44 |
$rewriteflag=1; //Set rewriting to on. |
|---|
| 45 |
fwrite($f_write,trim($Replacestring)."\n"); //If both strings are equal, replace original entry with new entry. |
|---|
| 46 |
|
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
else fwrite($f_write,trim($line)."\n"); //No strings match, just write original line. |
|---|
| 50 |
|
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
if ($rewriteflag==0) fwrite($f_write,trim($Replacestring)."\n"); //Add new entries |
|---|
| 54 |
|
|---|
| 55 |
rename("/etc/asterisk/mytemp.conf","/etc/asterisk/".$Filename); //Renames temp file. |
|---|
| 56 |
|
|---|
| 57 |
//Close both files |
|---|
| 58 |
fclose($f_read); |
|---|
| 59 |
fclose($f_write); |
|---|
| 60 |
|
|---|
| 61 |
return; |
|---|
| 62 |
|
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
Function agentadministration_getdropdownlist() { |
|---|
| 67 |
|
|---|
| 68 |
// This function is used for the agent dropdown list. This will put all agents ids and name in one huge string |
|---|
| 69 |
|
|---|
| 70 |
$f_agents=fopen("/etc/asterisk/agents.conf","r"); //Read the original agents.conf file |
|---|
| 71 |
|
|---|
| 72 |
$gridname_totalentries=""; |
|---|
| 73 |
|
|---|
| 74 |
while ($line=fgets($f_agents,9000) ) { |
|---|
| 75 |
|
|---|
| 76 |
$substring=substr($line,0,8); //Find the "agent =>" part. |
|---|
| 77 |
|
|---|
| 78 |
if ($substring=="agent =>") { |
|---|
| 79 |
|
|---|
| 80 |
//This part concatenates the individual agent entries into one huge string |
|---|
| 81 |
if ($gridname_totalentries=="") $gridname_totalentries=agentadministration_reformatnameentry($line,0); //For the very first line |
|---|
| 82 |
|
|---|
| 83 |
else $gridname_totalentries=$gridname_totalentries.",".agentadministration_reformatnameentry($line,0); //For every other line |
|---|
| 84 |
|
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
//Close file |
|---|
| 90 |
fclose($f_agents); |
|---|
| 91 |
|
|---|
| 92 |
return $gridname_totalentries; |
|---|
| 93 |
|
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
Function agentadministration_getlargestagentid() { |
|---|
| 98 |
|
|---|
| 99 |
//This function will get the larget Agent ID contained in the dropdown list. |
|---|
| 100 |
|
|---|
| 101 |
$f_agents=fopen("/etc/asterisk/agents.conf","r"); //Read the original agents.conf file |
|---|
| 102 |
$LargestAgentID=0; |
|---|
| 103 |
|
|---|
| 104 |
while ($line=fgets($f_agents,9000) ) { |
|---|
| 105 |
|
|---|
| 106 |
$substring=substr($line,0,8); //Find the "agent =>" part. |
|---|
| 107 |
|
|---|
| 108 |
if ($substring=="agent =>") { |
|---|
| 109 |
|
|---|
| 110 |
//This part just keeps the largest AgentID |
|---|
| 111 |
if (agentadministration_reformatnameentry($line,1)>$LargestAgentID && agentadministration_reformatnameentry($line,1)<2008) $LargestAgentID=agentadministration_reformatnameentry($line,1); |
|---|
| 112 |
|
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
//Close file |
|---|
| 118 |
fclose($f_agents); |
|---|
| 119 |
|
|---|
| 120 |
return $LargestAgentID; |
|---|
| 121 |
|
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
Function agentadministration_getagentinfo($currentagentid,$largestagentid) { |
|---|
| 126 |
|
|---|
| 127 |
//This function returns the all information of the agent chosen from the dropdown to be used for the text boxes |
|---|
| 128 |
|
|---|
| 129 |
//An agent is chosen from the dropdown, just get the necessary information |
|---|
| 130 |
if ($currentagentid>0) { |
|---|
| 131 |
|
|---|
| 132 |
$agentinfo=str_replace("::",":",$currentagentid); //Replace :: with single : |
|---|
| 133 |
|
|---|
| 134 |
$data=explode(":",$agentinfo); //Put in array |
|---|
| 135 |
|
|---|
| 136 |
/* |
|---|
| 137 |
|
|---|
| 138 |
$data [0] - Agent ID |
|---|
| 139 |
$data [1] - Agent Name |
|---|
| 140 |
$data [2] - Agent Password |
|---|
| 141 |
|
|---|
| 142 |
*/ |
|---|
| 143 |
|
|---|
| 144 |
$title="Agent: ".$data[1]." (".$data[0].")"; //The Agent title |
|---|
| 145 |
|
|---|
| 146 |
$NextAgentID=$data[0]; //The Agent ID |
|---|
| 147 |
|
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
//If adding a new agent |
|---|
| 151 |
else { |
|---|
| 152 |
|
|---|
| 153 |
$title="Add Agent"; //The default title |
|---|
| 154 |
$NextAgentID=$largestagentid+1; //Setup for next Agent ID |
|---|
| 155 |
$data[0]=$NextAgentID; |
|---|
| 156 |
$data[1]=""; |
|---|
| 157 |
$data[2]=""; |
|---|
| 158 |
|
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
$info=$title.",".$NextAgentID.",".$data[1].",".$data[0].",".$data[2]; //Returns Agent title, next Agent name, Agent IS, and Agent password. |
|---|
| 162 |
|
|---|
| 163 |
return $info; |
|---|
| 164 |
|
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
?> |
|---|