Added Territories admin page for use in custom Vtiger installs

git-svn-id: svn://192.168.202.10@1122 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2009-05-21 09:52:19 +00:00
parent 2939a69550
commit 845fc52237
9 changed files with 1035 additions and 12 deletions
+1 -1
View File
@@ -736,7 +736,7 @@ while ($sthBrowsC > $i)
if ($VL_exists > 0)
{
$user='';
$stmtA = "SELECT user FROM vicidial_user_territories where territory='$territory';";
$stmtA = "SELECT user FROM vicidial_user_territories where territory='$territory' order by level desc,user;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
+1 -1
View File
@@ -12,7 +12,7 @@ vicidial.php agent screen and vdc_db_query.php scripts have been changed to allo
AST_VDauto_dial.pl, AST_VDauto_dial_FILL.pl and the VDhangup process in FastAGI_log.pl have all been modified to work with the new alt number data structure.
non_agent_api.php needs to be changed to accept new multiple-al-numbers per inserted lead.
non_agent_api.php needs to be changed to accept new multiple-alt-numbers per inserted lead.
File structure for CLI lead loader goes here:
+11 -2
View File
@@ -1101,7 +1101,8 @@ sounds_central_control_active ENUM('0','1') default '0',
sounds_web_server VARCHAR(15) default '127.0.0.1',
sounds_web_directory VARCHAR(255) default '',
active_voicemail_server VARCHAR(15) default '',
auto_dial_limit VARCHAR(5) default '4'
auto_dial_limit VARCHAR(5) default '4',
user_territories_active ENUM('0','1') default '0'
);
CREATE TABLE vicidial_campaigns_list_mix (
@@ -1506,10 +1507,18 @@ unique index menuoption (menu_id, option_value)
CREATE TABLE vicidial_user_territories (
user VARCHAR(20) NOT NULL,
territory VARCHAR(100) default '',
level ENUM('TOP_AGENT','STANDARD_AGENT','BOTTOM_AGENT') default 'STANDARD_AGENT',
index (user),
unique index userterritory (user, territory)
);
CREATE TABLE vicidial_territories (
territory_id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
territory VARCHAR(100) default '',
territory_description VARCHAR(255) default '',
unique index uniqueterritory (territory)
);
ALTER TABLE vicidial_campaign_server_stats ENGINE=HEAP;
@@ -1606,7 +1615,7 @@ CREATE INDEX phone_number on vicidial_closer_log (phone_number);
CREATE INDEX date_user on vicidial_closer_log (call_date,user);
CREATE INDEX comment_a on live_inbound_log (comment_a);
UPDATE system_settings SET db_schema_version='1143';
UPDATE system_settings SET db_schema_version='1144';
GRANT RELOAD ON *.* TO cron@'%';
GRANT RELOAD ON *.* TO cron@localhost;
+13
View File
@@ -103,3 +103,16 @@ ALTER TABLE system_settings ADD active_voicemail_server VARCHAR(15) default '';
ALTER TABLE system_settings ADD auto_dial_limit VARCHAR(5) default '4';
UPDATE system_settings SET db_schema_version='1143';
CREATE TABLE vicidial_territories (
territory_id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
territory VARCHAR(100) default '',
territory_description VARCHAR(255) default '',
unique index uniqueterritory (territory)
);
ALTER TABLE vicidial_user_territories ADD level ENUM('TOP_AGENT','STANDARD_AGENT','BOTTOM_AGENT') default 'STANDARD_AGENT';
ALTER TABLE system_settings ADD user_territories_active ENUM('0','1') default '0';
UPDATE system_settings SET db_schema_version='1144';
@@ -119,8 +119,42 @@ Active Voicemail Server||
In multi-server systems, this is the server that will handle all voicemail boxes. This server is also where the dial-in generated prompts will be uploaded from, the 8168 recordings||
Auto Dial Limit||
This is the maximum limit of the auto dial level in the campaign screen||
User Territories are not active on this system||
User Territories||
List All Territories:||
User Territories Active||
This setting allows you to enable the User Territories setttings from the user modification screen. This feature was added to allow for more integration with a customized Vtiger installation but can have applications in a pure ViciDial system as well. Default is 0 for disabled||
List Territories||
Add Territory||
Add User Territory||
Territory||
Territory Description||
Territory and Territory Description must be filled in||
there is already a territory in the system with this name||
Territory Added||
Modify Territory||
Territory not found||
This territory is not in the system with this name||
Territory Modified||
Territory must be filled in||
Territory Deleted||
Delete This Territory||
Vtiger Accounts||
Agents||
Territory, User and Level must be filled in||
this territory user is already in the system||
User Territory Added||
this territory user is not in the system||
User Territory Modified||
Territory and User must be filled in||
User Territory Deleted||
Vtiger Change Territory Owner||
Had to add user territory||
Vtiger Territory Owner Changed||
Records Changed||
add-file: user_territories.php
add-file: audio_store.php
############################################################ CLIENT
+20 -7
View File
@@ -1024,6 +1024,8 @@ if (isset($_GET["active_voicemail_server"])) {$active_voicemail_server=$_GET["
elseif (isset($_POST["active_voicemail_server"])) {$active_voicemail_server=$_POST["active_voicemail_server"];}
if (isset($_GET["auto_dial_limit"])) {$auto_dial_limit=$_GET["auto_dial_limit"];}
elseif (isset($_POST["auto_dial_limit"])) {$auto_dial_limit=$_POST["auto_dial_limit"];}
if (isset($_GET["user_territories_active"])) {$user_territories_active=$_GET["user_territories_active"];}
elseif (isset($_POST["user_territories_active"])) {$user_territories_active=$_POST["user_territories_active"];}
if (isset($script_id)) {$script_id= strtoupper($script_id);}
if (isset($lead_filter_id)) {$lead_filter_id = strtoupper($lead_filter_id);}
@@ -1215,6 +1217,7 @@ $track_in_vdac = ereg_replace("[^0-9]","",$track_in_vdac);
$menu_repeat = ereg_replace("[^0-9]","",$menu_repeat);
$agentonly_callback_campaign_lock = ereg_replace("[^0-9]","",$agentonly_callback_campaign_lock);
$sounds_central_control_active = ereg_replace("[^0-9]","",$sounds_central_control_active);
$user_territories_active = ereg_replace("[^0-9]","",$user_territories_active);
### DIGITS and COLONS
$shift_length = ereg_replace("[^\:0-9]","",$shift_length);
@@ -1766,11 +1769,12 @@ $dialplan_entry = ereg_replace("\r","",$dialplan_entry);
# 90511-0910 - Added agentonly_callback_campaign_lock to system_settings
# 90512-0440 - Added sounds settings to system_settings table
# 90514-0607 - Added select prompts from list in call menu and in-group screens
# 90521-0029 - Added select prompts from list in call menu and in-group screens
#
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time
$admin_version = '2.2.0-185';
$build = '90514-0607';
$admin_version = '2.2.0-186';
$build = '90521-0029';
$STARTtime = date("U");
$SQLdate = date("Y-m-d H:i:s");
@@ -1816,7 +1820,7 @@ if ($force_logout)
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,auto_dial_limit FROM system_settings;";
$stmt = "SELECT use_non_latin,auto_dial_limit,user_territories_active FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
@@ -1824,8 +1828,9 @@ $i=0;
while ($i < $qm_conf_ct)
{
$row=mysql_fetch_row($rslt);
$non_latin = $row[0];
$SSauto_dial_limit = $row[1];
$non_latin = $row[0];
$SSauto_dial_limit = $row[1];
$SSuser_territories_active = $row[2];
$i++;
}
##### END SETTINGS LOOKUP #####
@@ -5244,6 +5249,11 @@ FR_SPAC 00 00 00 00 00 - France space separated phone number<BR>
<BR>
<B>Max FILL Calls per Second -</B> This setting determines the maximum number of calls that can be placed by the auto-FILL outbound auto-dialing script on for all servers, per second. Must be from 1 to 200. Default is 40.
<BR>
<A NAME="settings-user_territories_active">
<BR>
<B>User Territories Active -</B> This setting allows you to enable the User Territories setttings from the user modification screen. This feature was added to allow for more integration with a customized Vtiger installation but can have applications in a pure ViciDial system as well. Default is 0 for disabled.
<BR>
<A NAME="settings-qc_features_active">
<BR>
@@ -11636,7 +11646,7 @@ if ($ADD==411111111111111)
echo "<br>VICIDIAL SYSTEM SETTINGS MODIFIED\n";
$stmt="UPDATE system_settings set use_non_latin='$use_non_latin',webroot_writable='$webroot_writable',enable_queuemetrics_logging='$enable_queuemetrics_logging',queuemetrics_server_ip='$queuemetrics_server_ip',queuemetrics_dbname='$queuemetrics_dbname',queuemetrics_login='$queuemetrics_login',queuemetrics_pass='$queuemetrics_pass',queuemetrics_url='$queuemetrics_url',queuemetrics_log_id='$queuemetrics_log_id',queuemetrics_eq_prepend='$queuemetrics_eq_prepend',vicidial_agent_disable='$vicidial_agent_disable',allow_sipsak_messages='$allow_sipsak_messages',admin_home_url='$admin_home_url',enable_agc_xfer_log='$enable_agc_xfer_log',timeclock_end_of_day='$timeclock_end_of_day',vdc_header_date_format='$vdc_header_date_format',vdc_customer_date_format='$vdc_customer_date_format',vdc_header_phone_format='$vdc_header_phone_format',vdc_agent_api_active='$vdc_agent_api_active',enable_vtiger_integration='$enable_vtiger_integration',vtiger_server_ip='$vtiger_server_ip',vtiger_dbname='$vtiger_dbname',vtiger_login='$vtiger_login',vtiger_pass='$vtiger_pass',vtiger_url='$vtiger_url',qc_features_active='$qc_features_active',outbound_autodial_active='$outbound_autodial_active',outbound_calls_per_second='$outbound_calls_per_second',agentonly_callback_campaign_lock='$agentonly_callback_campaign_lock',sounds_central_control_active='$sounds_central_control_active',sounds_web_server='$sounds_web_server',sounds_web_directory='$sounds_web_directory',active_voicemail_server='$active_voicemail_server',auto_dial_limit='$auto_dial_limit';";
$stmt="UPDATE system_settings set use_non_latin='$use_non_latin',webroot_writable='$webroot_writable',enable_queuemetrics_logging='$enable_queuemetrics_logging',queuemetrics_server_ip='$queuemetrics_server_ip',queuemetrics_dbname='$queuemetrics_dbname',queuemetrics_login='$queuemetrics_login',queuemetrics_pass='$queuemetrics_pass',queuemetrics_url='$queuemetrics_url',queuemetrics_log_id='$queuemetrics_log_id',queuemetrics_eq_prepend='$queuemetrics_eq_prepend',vicidial_agent_disable='$vicidial_agent_disable',allow_sipsak_messages='$allow_sipsak_messages',admin_home_url='$admin_home_url',enable_agc_xfer_log='$enable_agc_xfer_log',timeclock_end_of_day='$timeclock_end_of_day',vdc_header_date_format='$vdc_header_date_format',vdc_customer_date_format='$vdc_customer_date_format',vdc_header_phone_format='$vdc_header_phone_format',vdc_agent_api_active='$vdc_agent_api_active',enable_vtiger_integration='$enable_vtiger_integration',vtiger_server_ip='$vtiger_server_ip',vtiger_dbname='$vtiger_dbname',vtiger_login='$vtiger_login',vtiger_pass='$vtiger_pass',vtiger_url='$vtiger_url',qc_features_active='$qc_features_active',outbound_autodial_active='$outbound_autodial_active',outbound_calls_per_second='$outbound_calls_per_second',agentonly_callback_campaign_lock='$agentonly_callback_campaign_lock',sounds_central_control_active='$sounds_central_control_active',sounds_web_server='$sounds_web_server',sounds_web_directory='$sounds_web_directory',active_voicemail_server='$active_voicemail_server',auto_dial_limit='$auto_dial_limit',user_territories_active='$user_territories_active';";
$rslt=mysql_query($stmt, $link);
### LOG INSERTION Admin Log Table ###
@@ -19056,7 +19066,7 @@ if ($ADD==311111111111111)
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
$stmt="SELECT version,install_date,use_non_latin,webroot_writable,enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_url,queuemetrics_log_id,queuemetrics_eq_prepend,vicidial_agent_disable,allow_sipsak_messages,admin_home_url,enable_agc_xfer_log,db_schema_version,auto_user_add_value,timeclock_end_of_day,timeclock_last_reset_date,vdc_header_date_format,vdc_customer_date_format,vdc_header_phone_format,vdc_agent_api_active,qc_last_pull_time,enable_vtiger_integration,vtiger_server_ip,vtiger_dbname,vtiger_login,vtiger_pass,vtiger_url,qc_features_active,outbound_autodial_active,outbound_calls_per_second,agentonly_callback_campaign_lock,sounds_central_control_active,sounds_web_server,sounds_web_directory,active_voicemail_server,auto_dial_limit from system_settings;";
$stmt="SELECT version,install_date,use_non_latin,webroot_writable,enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_url,queuemetrics_log_id,queuemetrics_eq_prepend,vicidial_agent_disable,allow_sipsak_messages,admin_home_url,enable_agc_xfer_log,db_schema_version,auto_user_add_value,timeclock_end_of_day,timeclock_last_reset_date,vdc_header_date_format,vdc_customer_date_format,vdc_header_phone_format,vdc_agent_api_active,qc_last_pull_time,enable_vtiger_integration,vtiger_server_ip,vtiger_dbname,vtiger_login,vtiger_pass,vtiger_url,qc_features_active,outbound_autodial_active,outbound_calls_per_second,agentonly_callback_campaign_lock,sounds_central_control_active,sounds_web_server,sounds_web_directory,active_voicemail_server,auto_dial_limit,user_territories_active from system_settings;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$version = $row[0];
@@ -19099,6 +19109,7 @@ if ($ADD==311111111111111)
$sounds_web_directory = $row[37];
$active_voicemail_server = $row[38];
$auto_dial_limit = $row[39];
$user_territories_active = $row[40];
echo "<br>MODIFY VICIDIAL SYSTEM SETTINGS<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=ADD value=411111111111111>\n";
@@ -19236,6 +19247,8 @@ if ($ADD==311111111111111)
echo "<tr bgcolor=#B6D3FC><td align=right>Max FILL Calls per Second: </td><td align=left><input type=text name=outbound_calls_per_second size=4 maxlength=3 value=\"$outbound_calls_per_second\">$NWB#settings-outbound_calls_per_second$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>User Territories Active: </td><td align=left><select size=1 name=user_territories_active><option>1</option><option>0</option><option selected>$user_territories_active</option></select>$NWB#settings-user_territories_active$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>QC Features Active: </td><td align=left><select size=1 name=qc_features_active><option>1</option><option>0</option><option selected>$qc_features_active</option></select>$NWB#settings-qc_features_active$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>QC Last Pull Time: </td><td align=left> $qc_last_pull_time</td></tr>\n";
+8
View File
@@ -480,7 +480,15 @@ $admin_home_url_LU = $row[0];
&nbsp; <a href="./user_status.php?user=<?php echo $user ?>"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>>User Status </a>
</TR><TR BGCOLOR=<?php echo $users_color ?>><TD ALIGN=LEFT>
&nbsp; <a href="./AST_agent_time_sheet.php?agent=<?php echo $user ?>"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>>Time Sheet </a> </TD></TR>
<?php
if ( ($SSuser_territories_active > 0) or ($user_territories_active > 0) )
{ ?>
</TR><TR BGCOLOR=<?php echo $users_color ?>><TD ALIGN=LEFT>
&nbsp; <a href="./user_territories.php?agent=<?php echo $user ?>"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>>User Territories </a> </TD></TR>
<?php }
}
?>
<!-- CAMPAIGNS NAVIGATION -->
<TR><TD <?php echo $campaigns_hh ?>>
+2 -1
View File
@@ -43,7 +43,7 @@ header ("Pragma: no-cache"); // HTTP/1.0
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,sounds_central_control_active,sounds_web_server,sounds_web_directory FROM system_settings;";
$stmt = "SELECT use_non_latin,sounds_central_control_active,sounds_web_server,sounds_web_directory,outbound_autodial_active FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$ss_conf_ct = mysql_num_rows($rslt);
@@ -54,6 +54,7 @@ if ($ss_conf_ct > 0)
$sounds_central_control_active = $row[1];
$sounds_web_server = $row[2];
$sounds_web_directory = $row[3];
$SSoutbound_autodial_active = $row[4];
}
##### END SETTINGS LOOKUP #####
###########################################
+945
View File
@@ -0,0 +1,945 @@
<?php
# user_territories.php
#
# Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# This territories script is for use with custom tables in Vtiger which is why
# it is separate from the standard admin.php script. user_territories_active in
# the system_settings table must be active for this script to work.
#
# CHANGES
# 90520-1928 - first build
#
$version = '2.2.0-1';
$build = '90520-1928';
$MT[0]='';
require("dbconnect.php");
$PHP_SELF=$_SERVER['PHP_SELF'];
if (isset($_GET["action"])) {$action=$_GET["action"];}
elseif (isset($_POST["action"])) {$action=$_POST["action"];}
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["territory"])) {$territory=$_GET["territory"];}
elseif (isset($_POST["territory"])) {$territory=$_POST["territory"];}
if (isset($_GET["territory_description"])) {$territory_description=$_GET["territory_description"];}
elseif (isset($_POST["territory_description"])) {$territory_description=$_POST["territory_description"];}
if (isset($_GET["user"])) {$user=$_GET["user"];}
elseif (isset($_POST["user"])) {$user=$_POST["user"];}
if (isset($_GET["level"])) {$level=$_GET["level"];}
elseif (isset($_POST["level"])) {$level=$_POST["level"];}
if (isset($_GET["accountid"])) {$accountid=$_GET["accountid"];}
elseif (isset($_POST["accountid"])) {$accountid=$_POST["accountid"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
header ("Content-type: text/html; charset=utf-8");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,user_territories_active,enable_vtiger_integration,outbound_autodial_active,vtiger_server_ip,vtiger_dbname,vtiger_login,vtiger_pass,vtiger_url FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$ss_conf_ct = mysql_num_rows($rslt);
if ($ss_conf_ct > 0)
{
$row=mysql_fetch_row($rslt);
$non_latin = $row[0];
$user_territories_active = $row[1];
$enable_vtiger_integration = $row[2];
$SSoutbound_autodial_active = $row[3];
$vtiger_server_ip = $row[4];
$vtiger_dbname = $row[5];
$vtiger_login = $row[6];
$vtiger_pass = $row[7];
$vtiger_url = $row[8];
}
##### END SETTINGS LOOKUP #####
###########################################
### check if sounds server matches this server IP, if not then exit with an error
if ($user_territories_active < 1)
{
echo "ERROR: User Territories are not active on this system\n";
exit;
}
if ($non_latin < 1)
{
### Clean Variable Values ###
$DB = ereg_replace("[^0-9]","",$DB);
$action = ereg_replace("[^\_0-9a-zA-Z]","",$action);
$territory = ereg_replace("[^-\_0-9a-zA-Z]","",$territory);
$territory_description = ereg_replace("[^ -\_\.\,0-9a-zA-Z]","",$territory_description);
$user = ereg_replace("[^-\_0-9a-zA-Z]","",$user);
$level = ereg_replace("[^\_A-Z]","",$level);
$old_territory = ereg_replace("[^-\_0-9a-zA-Z]","",$old_territory);
$old_user = ereg_replace("[^-\_0-9a-zA-Z]","",$old_user);
}
$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER);
$PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW);
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7 and modify_users='1'";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$auth=$row[0];
if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth))
{
Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n";
exit;
}
if ($enable_vtiger_integration > 0)
{
### connect to your vtiger database
$linkV=mysql_connect("$vtiger_server_ip", "$vtiger_login","$vtiger_pass");
if (!$linkV) {die("Could not connect: $vtiger_server_ip|$vtiger_dbname|$vtiger_login|$vtiger_pass" . mysql_error());}
mysql_select_db("$vtiger_dbname", $linkV);
}
if (strlen($action) < 1)
{$action = 'LIST_ALL_TERRITORIES';}
?>
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<!-- VERSION: <?php echo $version ?> BUILD: <?php echo $build ?> -->
<title>VICIDIAL ADMINISTRATION: User Territories
<?php
### BEGIN change territory owner for one account
if ( ($action == "CHANGE_TERRITORY_OWNER_ACCOUNT") and ($enable_vtiger_integration > 0) )
{
echo "</TITLE></HEAD><BODY BGCOLOR=white>\n";
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>Vtiger Change Territory Owner<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=PROCESS_CHANGE_TERRITORY_OWNER_ACCOUNT>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Account ID: </td><td align=left><input type=text name=accountid value=\"$accountid\"></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>New Owner: </td><td align=left><select size=1 name=user>\n";
$stmt="SELECT user,full_name from vicidial_users where active='Y' order by user";
$rslt=mysql_query($stmt, $link);
$users_to_print = mysql_num_rows($rslt);
$users_list='';
$o=0;
while ($users_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$users_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "$users_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
echo "</TABLE></center>\n";
exit;
}
### END change territory owner for one account
### BEGIN process change territory owner for one account
if ( ($action == "PROCESS_CHANGE_TERRITORY_OWNER_ACCOUNT") and ($enable_vtiger_integration > 0) )
{
echo "</TITLE></HEAD><BODY BGCOLOR=white>\n";
if ( (strlen($accountid)<1) or (strlen($user)<1) )
{
echo "ERROR: Account ID and User must be filled in<BR>\n";
}
else
{
$stmtV="SELECT tickersymbol from vtiger_account where accountid='$accountid';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vat_ct = mysql_num_rows($rsltV);
if ($vat_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$territory = $row[0];
$stmt="SELECT count(*) from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 1)
{
$stmt="INSERT INTO vicidial_user_territories SET territory='$territory',user='$user',level='STANDARD_AGENT';";
$rslt=mysql_query($stmt, $link);
echo "NOTICE: Had to add user territory: $user $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='ADD', record_id='$territory', event_code='ADMIN ADD USER TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
$stmtV="SELECT id from vtiger_users where user_name='$user';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vtu_ct = mysql_num_rows($rsltV);
if ($vtu_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$user_id = $row[0];
$stmt="UPDATE vtiger_crmentity SET smownerid='$user_id',smcreatorid='$user_id',modifiedby='$user_id' where crmid='$accountid';";
$rsltV=mysql_query($stmt, $linkV);
$changed = mysql_affected_rows($linkV);
$stmtB="UPDATE vtiger_tracker SET user_id='$user_id' where item_id='$accountid';";
$rsltV=mysql_query($stmtB, $linkV);
echo "Vtiger Territory Owner Changed: $user $territory<BR>\n";
echo "Records Changed: $changed<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='VTIGER', event_type='MODIFY', record_id='$accountid', event_code='VTIGER MODIFY TERRITORY OWNER ACCOUNT', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
}
exit;
}
### END process change territory owner for one account
##### BEGIN Set variables to make header show properly #####
$ADD = '0';
$hh = 'users';
$LOGast_admin_access = '1';
$ADMIN = 'admin.php';
$page_width='770';
$section_width='750';
$header_font_size='3';
$subheader_font_size='2';
$subcamp_font_size='2';
$header_selected_bold='<b>';
$header_nonselected_bold='';
$users_color = '#FFFF99';
$users_font = 'BLACK';
$users_color = '#E6E6E6';
$subcamp_color = '#C6C6C6';
##### END Set variables to make header show properly #####
require("admin_header.php");
$colspan='3';
?>
<TABLE WIDTH=<?php echo $page_width ?> BGCOLOR=#E6E6E6 cellpadding=2 cellspacing=0>
<TR BGCOLOR=#E6E6E6>
<TD ALIGN=LEFT><FONT FACE="ARIAL,HELVETICA" SIZE=2><B> &nbsp; <a href="<?php echo "$PHP_SELF" ?>">List Territories</a></TD>
<TD ALIGN=RIGHT><FONT FACE="ARIAL,HELVETICA" SIZE=2><B> &nbsp; <a href="<?php echo "$PHP_SELF" ?>?action=ADD_TERRITORY">Add Territory</a></TD>
<TD ALIGN=RIGHT><FONT FACE="ARIAL,HELVETICA" SIZE=2><B> &nbsp; <a href="<?php echo "$PHP_SELF" ?>?action=ADD_USER_TERRITORY">Add User Territory</a></TD>
<?
if ($enable_vtiger_integration > 0)
{ ?>
<TD ALIGN=RIGHT><FONT FACE="ARIAL,HELVETICA" SIZE=2><B> &nbsp; <a href="<?php echo "$PHP_SELF" ?>?action=CHANGE_TERRITORY_OWNER">Change Vtiger Territory Owner</a></TD>
<?
$colspan='4';
} ?>
</TR>
<?php
echo "<TR BGCOLOR=\"#F0F5FE\"><TD ALIGN=LEFT COLSPAN=$colspan><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=3><B> &nbsp; \n";
$STARTtime = date("U");
$TODAY = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$FILE_datetime = $STARTtime;
$ip = getenv("REMOTE_ADDR");
$date = date("r");
$browser = getenv("HTTP_USER_AGENT");
$script_name = getenv("SCRIPT_NAME");
$server_name = getenv("SERVER_NAME");
$server_port = getenv("SERVER_PORT");
if (eregi("443",$server_port)) {$HTTPprotocol = 'https://';}
else {$HTTPprotocol = 'http://';}
$admDIR = "$HTTPprotocol$server_name:$server_port$script_name";
$admDIR = eregi_replace('audio_store.php','',$admDIR);
$admSCR = 'admin.php';
$NWB = " &nbsp; <a href=\"javascript:openNewWindow('$admDIR$admSCR?ADD=99999";
$NWE = "')\"><IMG SRC=\"help.gif\" WIDTH=20 HEIGHT=20 BORDER=0 ALT=\"HELP\" ALIGN=TOP></A>";
$secX = date("U");
$pulldate0 = "$year-$mon-$mday $hour:$min:$sec";
### BEGIN change territory owner in the system
if ( ($action == "CHANGE_TERRITORY_OWNER") and ($enable_vtiger_integration > 0) )
{
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>Vtiger Change Territory Owner<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=PROCESS_CHANGE_TERRITORY_OWNER>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory: </td><td align=left><select size=1 name=territory>\n";
$stmt="SELECT territory,territory_description from vicidial_territories order by territory";
$rslt=mysql_query($stmt, $link);
$territories_to_print = mysql_num_rows($rslt);
$territories_list='';
$o=0;
while ($territories_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$territories_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "$territories_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>New Owner: </td><td align=left><select size=1 name=user>\n";
$stmt="SELECT user,full_name from vicidial_users where active='Y' order by user";
$rslt=mysql_query($stmt, $link);
$users_to_print = mysql_num_rows($rslt);
$users_list='';
$o=0;
while ($users_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$users_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "$users_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
echo "</TABLE></center>\n";
}
### END change territory owner in the system
### BEGIN process change territory owner in the system
if ( ($action == "PROCESS_CHANGE_TERRITORY_OWNER") and ($enable_vtiger_integration > 0) )
{
if ( (strlen($territory)<1) or (strlen($user)<1) )
{
echo "ERROR: Territory and User must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 1)
{
$stmt="INSERT INTO vicidial_user_territories SET territory='$territory',user='$user',level='TOP_AGENT';";
$rslt=mysql_query($stmt, $link);
$stmtB="UPDATE vicidial_user_territories SET level='STANDARD_AGENT' where territory='$territory' and user!='$user' and level='TOP_AGENT';";
$rslt=mysql_query($stmtB, $link);
echo "NOTICE: Had to add user territory: $user $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='ADD', record_id='$territory', event_code='ADMIN ADD USER TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
$stmtV="SELECT id from vtiger_users where user_name='$user';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vtu_ct = mysql_num_rows($rsltV);
if ($vtu_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$user_id = $row[0];
$stmt="UPDATE vtiger_crmentity SET smownerid='$user_id',smcreatorid='$user_id',modifiedby='$user_id' where crmid IN(SELECT accountid from vtiger_account where tickersymbol='$territory');";
$rsltV=mysql_query($stmt, $linkV);
$changed = mysql_affected_rows($linkV);
$stmtB="UPDATE vtiger_tracker vt, vtiger_account va SET user_id='$user_id' where vt.item_id=va.accountid and va.tickersymbol='$territory';";
$rsltV=mysql_query($stmtB, $linkV);
echo "Vtiger Territory Owner Changed: $user $territory &nbsp; &nbsp; &nbsp; Records Changed: $changed<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='VTIGER', event_type='MODIFY', record_id='$territory', event_code='VTIGER MODIFY TERRITORY OWNER', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "MODIFY_TERRITORY";
}
### END process change territory owner in the system
### BEGIN add user territory page
if ($action == "ADD_USER_TERRITORY")
{
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>Add User Territory<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=PROCESS_ADD_USER_TERRITORY>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Agent: </td><td align=left><select size=1 name=user>\n";
$stmt="SELECT user,full_name from vicidial_users where active='Y' order by user";
$rslt=mysql_query($stmt, $link);
$users_to_print = mysql_num_rows($rslt);
$users_list='';
$o=0;
while ($users_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$users_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "$users_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory: </td><td align=left><select size=1 name=territory>\n";
$stmt="SELECT territory,territory_description from vicidial_territories order by territory";
$rslt=mysql_query($stmt, $link);
$territories_to_print = mysql_num_rows($rslt);
$territories_list='';
$o=0;
while ($territories_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$territories_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "$territories_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Level: </td><td align=left><select size=1 name=level><option>TOP_AGENT</option><option>STANDARD_AGENT</option><option>BOTTOM_AGENT</option></select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
echo "</TABLE></center>\n";
}
### END add user territory page
### BEGIN process add user territory page
if ($action == "PROCESS_ADD_USER_TERRITORY")
{
if ( (strlen($territory)<1) or (strlen($user)<1) or (strlen($level)<1) )
{
echo "ERROR: Territory, User and Level must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] > 0)
{
echo "ERROR: this territory user is already in the system<BR>\n";
}
else
{
$stmt="INSERT INTO vicidial_user_territories SET territory='$territory',user='$user',level='$level';";
$rslt=mysql_query($stmt, $link);
if ($level == "TOP_AGENT")
{
$stmtB="UPDATE vicidial_user_territories SET level='STANDARD_AGENT' where territory='$territory' and user!='$user' and level='TOP_AGENT';";
$rslt=mysql_query($stmtB, $link);
}
echo "User Territory Added: $user $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='ADD', record_id='$territory', event_code='ADMIN ADD USER TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "MODIFY_TERRITORY";
}
### END process add user territory page
### BEGIN process modify user territory page
if ($action == "PROCESS_MODIFY_USER_TERRITORY")
{
if ( (strlen($territory)<1) or (strlen($user)<1) or (strlen($level)<1) )
{
echo "ERROR: Territory, User and Level must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 0)
{
echo "ERROR: this territory user is not in the system<BR>\n";
}
else
{
$stmt="UPDATE vicidial_user_territories SET level='$level' where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
if ($level == "TOP_AGENT")
{
$stmtB="UPDATE vicidial_user_territories SET level='STANDARD_AGENT' where territory='$territory' and user!='$user' and level='TOP_AGENT';";
$rslt=mysql_query($stmtB, $link);
}
echo "User Territory Modified: $user $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='MODIFY', record_id='$territory', event_code='ADMIN MODIFY USER TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "MODIFY_TERRITORY";
}
### END process modify user territory page
### BEGIN delete user territory page
if ($action == "DELETE_USER_TERRITORY")
{
if ( (strlen($territory)<1) or (strlen($user)<1) )
{
echo "ERROR: Territory and User must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 0)
{
echo "ERROR: this territory user is not in the system<BR>\n";
}
else
{
$stmt="DELETE from vicidial_user_territories where territory='$territory' and user='$user';";
$rslt=mysql_query($stmt, $link);
echo "User Territory Deleted: $user $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='DELETE', record_id='$territory', event_code='ADMIN DELETE USER TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "MODIFY_TERRITORY";
}
### END delete user territory page
### BEGIN add territory page
if ($action == "ADD_TERRITORY")
{
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>Add Territory<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=PROCESS_ADD_TERRITORY>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory: </td><td align=left><input type=text name=territory size=30 maxlength=100></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory Description: </td><td align=left><input type=text name=territory_description size=50 maxlength=255></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
echo "</TABLE></center>\n";
}
### END add territory page
### BEGIN process add territory page
if ($action == "PROCESS_ADD_TERRITORY")
{
if ( (strlen($territory)<1) or (strlen($territory_description)<1) )
{
echo "ERROR: Territory and Territory Description must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] > 0)
{
echo "ERROR: there is already a territory in the system with this name<BR>\n";
}
else
{
$stmt="INSERT INTO vicidial_territories SET territory='$territory',territory_description='$territory_description';";
$rslt=mysql_query($stmt, $link);
echo "Territory Added: $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='ADD', record_id='$territory', event_code='ADMIN ADD TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "LIST_ALL_TERRITORIES";
}
### END process add territory page
### BEGIN delete territory page
if ($action == "DELETE_TERRITORY")
{
if (strlen($territory)<1)
{
echo "ERROR: Territory must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 0)
{
echo "ERROR: This territory is not in the system with this name<BR>\n";
}
else
{
$stmt="DELETE from vicidial_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
echo "Territory Deleted: $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='DELETE', record_id='$territory', event_code='ADMIN DELETE TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "LIST_ALL_TERRITORIES";
}
### END delete territory page
### BEGIN process modify territory page
if ($action == "PROCESS_MODIFY_TERRITORY")
{
if ( (strlen($territory)<1) or (strlen($territory_description)<1) )
{
echo "ERROR: Territory and Territory Description must be filled in<BR>\n";
}
else
{
$stmt="SELECT count(*) from vicidial_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
if ($row[0] < 1)
{
echo "ERROR: This territory is not in the system with this name<BR>\n";
}
else
{
$stmt="UPDATE vicidial_territories SET territory_description='$territory_description' where territory='$territory';";
$rslt=mysql_query($stmt, $link);
echo "Territory Modified: $territory<BR>\n";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TERRITORIES', event_type='MODIFY', record_id='$territory', event_code='ADMIN MODIFY TERRITORY', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
$action = "MODIFY_TERRITORY";
}
### END process modify territory page
### BEGIN modify territory page
if ($action == "MODIFY_TERRITORY")
{
$stmt="SELECT territory,territory_description from vicidial_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
$territories_to_print = mysql_num_rows($rslt);
if ($territories_to_print > 0)
{
$rowx=mysql_fetch_row($rslt);
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>Modify Territory<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=PROCESS_MODIFY_TERRITORY>\n";
echo "<input type=hidden name=territory value=\"$territory\">\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory: </td><td align=left><B>$rowx[0]</B></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Territory Description: </td><td align=left><input type=text name=territory_description size=50 maxlength=255 value=\"$rowx[1]\"></td></tr>\n";
$stmt = "SELECT count(*) FROM vicidial_user_territories where territory='$territory';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$vut_ct = mysql_num_rows($rslt);
if ($vut_ct > 0)
{
$row=mysql_fetch_row($rslt);
$user_count = $row[0];
}
echo "<tr bgcolor=#B6D3FC><td align=right>Agents: </td><td align=left><B>$user_count</B></td></tr>";
if ($enable_vtiger_integration > 0)
{
$stmtV = "SELECT count(*) FROM vtiger_account where tickersymbol='$territory';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vta_ct = mysql_num_rows($rsltV);
if ($vta_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$vtiger_count = $row[0];
}
echo "<tr bgcolor=#B6D3FC><td align=right>Vtiger Accounts: </td><td align=left><B>$vtiger_count</B></td></tr>";
}
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value=SUBMIT></form></td></tr>\n";
echo "</TABLE></center>\n";
echo "<BR><BR>\n";
echo "<TABLE CELLPADDING=3 CELLSPACING=1 WIDTH=600><TR><TD COLSPAN=5><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>Users in this Territory:</TD></TR>\n";
$stmt="SELECT vut.user,level,full_name from vicidial_user_territories vut,vicidial_users vu where vut.territory='$territory' and vut.user=vu.user order by vu.user;";
$rslt=mysql_query($stmt, $link);
$territories_to_print = mysql_num_rows($rslt);
$o=0;
while ($territories_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$o++;
if (eregi("1$|3$|5$|7$|9$", $o))
{$bgcolor='bgcolor="#B9CBFD"';}
else
{$bgcolor='bgcolor="#9BB9FB"';}
echo "<TR $bgcolor><TD><font size=1>$o</TD>";
echo "<TD><a href=\"admin.php?ADD=3&user=$rowx[0]\">$rowx[0]</a></TD>";
echo "<TD>$rowx[2]</TD>";
if ($enable_vtiger_integration > 0)
{
$stmtV="SELECT id from vtiger_users where user_name='$rowx[0]';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vtu_ct = mysql_num_rows($rsltV);
if ($vtu_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$user_id = $row[0];
$stmtV = "SELECT count(*) FROM vtiger_account where tickersymbol='$territory' and accountid IN(SELECT crmid from vtiger_crmentity where smownerid='$user_id');";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$vca_ct = mysql_num_rows($rsltV);
if ($vca_ct > 0)
{
$row=mysql_fetch_row($rsltV);
echo "<TD>Accounts: $row[0]</TD>";
}
}
}
echo "<TD>";
echo "<form action=$PHP_SELF method=POST>";
echo "<input type=hidden name=action value=PROCESS_MODIFY_USER_TERRITORY>";
echo "<input type=hidden name=territory value=\"$territory\">";
echo "<input type=hidden name=user value=\"$rowx[0]\">";
echo "<select size=1 name=level><option SELECTED>$rowx[1]</option><option>TOP_AGENT</option><option>STANDARD_AGENT</option><option>BOTTOM_AGENT</option></select> ";
echo "<input type=submit name=submit value=submit>";
echo "</form>";
echo "</TD>";
echo "<TD><a href=\"$PHP_SELF?action=DELETE_USER_TERRITORY&territory=$territory&user=$rowx[0]\">DELETE</a></TD>";
echo "</TR>\n";
}
echo "</TABLE>\n";
echo "<BR><BR><BR>\n";
echo "<a href=\"$PHP_SELF?action=DELETE_TERRITORY&territory=$territory\">Delete This Territory</a>\n";
echo "<BR><BR>\n";
}
else
{
echo "ERROR: Territory not found: $territory<BR>\n";
}
}
### END modify territory page
### BEGIN list all territories in the system
if ($action == "LIST_ALL_TERRITORIES")
{
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br>List All Territories:\n";
echo "<center><TABLE width=$section_width cellspacing=0 cellpadding=1>\n";
echo "<TR BGCOLOR=BLACK>";
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>#</B></TD>";
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>ID</B></TD>";
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>TERRITORY</B></TD>";
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>DESCRIPTION</B></TD>\n";
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>AGENTS</TD>\n";
if ($enable_vtiger_integration > 0)
{
echo "<TD><B><FONT FACE=\"Arial,Helvetica\" size=1 color=white>VT ACCOUNTS</TD>\n";
}
echo "</TR>\n";
$stmt = "SELECT territory_id,territory,territory_description FROM vicidial_territories order by territory;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$vt_ct = mysql_num_rows($rslt);
$i=0;
while ($vt_ct > $i)
{
$row=mysql_fetch_row($rslt);
$Lterritory_id[$i] = $row[0];
$Lterritory[$i] = $row[1];
$Lterritory_description[$i] = $row[2];
$i++;
}
$i=0;
while ($vt_ct > $i)
{
$stmt = "SELECT count(*) FROM vicidial_user_territories where territory='$Lterritory[$i]';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$vut_ct = mysql_num_rows($rslt);
if ($vut_ct > 0)
{
$row=mysql_fetch_row($rslt);
$Lterritory_count[$i] = $row[0];
}
if ($enable_vtiger_integration > 0)
{
$stmtV = "SELECT count(*) FROM vtiger_account where tickersymbol='$Lterritory[$i]';";
$rsltV=mysql_query($stmtV, $linkV);
if ($DB) {echo "$stmtV\n";}
$va_ct = mysql_num_rows($rsltV);
if ($va_ct > 0)
{
$row=mysql_fetch_row($rsltV);
$Lvtiger_count[$i] = $row[0];
}
}
if (eregi("1$|3$|5$|7$|9$", $i))
{$bgcolor='bgcolor="#B9CBFD"';}
else
{$bgcolor='bgcolor="#9BB9FB"';}
echo "<tr $bgcolor><td><font size=1>$i</td>";
echo "<td><font size=1> $Lterritory_id[$i] </td>";
echo "<td><font size=1> <a href=\"$PHP_SELF?action=MODIFY_TERRITORY&territory=$Lterritory[$i]\">$Lterritory[$i]</a></td>";
echo "<td><font size=1> $Lterritory_description[$i]</td>";
echo "<td><font size=1> $Lterritory_count[$i]</td>";
if ($enable_vtiger_integration > 0)
{
echo "<td><font size=1> $Lvtiger_count[$i]</td>";
}
echo "</tr>\n";
$i++;
}
echo "</TABLE><BR><BR>\n";
echo "\n";
echo "</center>\n";
}
### END list all territories in the system
?>
<BR><font size=1>User Territories &nbsp; &nbsp; VERSION: <?php echo $version ?> &nbsp; &nbsp; BUILD: <?php echo $build ?> &nbsp; &nbsp; </td></tr>
</TD></TR></TABLE>