<commit_before><?php
#
# Copyright (C) 2008  <NAME> <<EMAIL>>      LICENSE: AGPLv2
# Copyright (C) 2009  <NAME>  <<EMAIL>>    LICENSE: AGPLv3
# Copyright (C) 2009  <NAME> <<EMAIL>>  LICENSE: AGPLv3
#
#     This file is part of OSDial.
#
#     OSDial is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of
#     the License, or (at your option) any later version.
#
#     OSDial is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public
#     License along with OSDial.  If not, see <http://www.gnu.org/licenses/>.
#


######################
# ADD=111111 display the ADD NEW AGENTS GROUP SCREEN
######################

if ($ADD==111111) {
    if ($LOG['modify_usergroups'] == 1 and $LOG['allowed_campaignsALL'] > 0) {
        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

        echo "<center>\n";
        echo "  <br><font color=$default_text size=+1>ADD NEW AGENTS GROUP</font><br><br>\n";
        echo "  <form action=$PHP_SELF method=POST>\n";
        echo "  <input type=hidden name=ADD value=211111>\n";
        echo "  <table width=$section_width cellspacing=3>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td width=40% align=right>Group: </td>\n";
        echo "      <td align=left>\n";
        if ($LOG['multicomp_admin'] > 0) {
            $comps = get_krh($link, 'osdial_companies', '*','',"status IN ('ACTIVE','INACTIVE','SUSPENDED')",'');
            echo "        <select name=company_id>\n";
            foreach ($comps as $comp) {
                echo "          <option value=$comp[id]>" . (($comp['id'] * 1) + 100) . ": " . $comp['name'] . "</option>\n";
            }
            echo "        </select>\n";
        } elseif ($LOG['multicomp']>0) {
            echo "        <input type=hidden name=company_id value=$LOG[company_id]>";
        }
        echo "        <input type=text name=user_group size=15 maxlength=20> $NWB#osdial_user_groups-user_group$NWE\n";
        echo "      </td>\n";
        echo "    </tr>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td align=right>Description: </td>\n";
        echo "      <td align=left><input type=text name=group_name size=40 maxlength=40> $NWB#osdial_user_groups-group_name$NWE</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
        echo "  </table>\n";
        echo "  </form>\n";
        echo "</center>\n";

        echo "</font>\n";
    } elseif ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT MODIFIED - You may only view your User Group resources.</font><br>\n";
    } else {
        echo "<font color=red>You do not have permission to view this page</font>\n";
    }
}


######################
# ADD=211111 adds new user group to the system
######################

if ($ADD==211111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    $preuser_group = $user_group;
    if ($LOG['multicomp'] > 0) $preuser_group = (($company_id * 1) + 100) . $user_group;
    $stmt="SELECT count(*) FROM osdial_user_groups WHERE user_group='$preuser_group';";
    $rslt=mysql_query($stmt, $link);
    $row=mysql_fetch_row($rslt);
    if ($row[0] > 0) {
        echo "<br><font color=red>USER GROUP NOT ADDED - there is already a user group entry with this name</font>\n";
    } else {
         if (strlen($user_group) < 2 or strlen($group_name) < 2) {
             echo "<br><font color=red>USER GROUP NOT ADDED - Please go back and look at the data you entered\n";
             echo "<br>Group name and description must be at least 2 characters in length</font><br>\n";
         } else {
            if ($LOG['multicomp'] > 0) $user_group = (($company_id * 1) + 100) . $user_group;
            $LOG['allowed_usergroupsSQL'] = rtrim($LOG['allowed_usergroupsSQL'],')');
            $LOG['allowed_usergroupsSQL'] .= ",'$user_group')";
            $LOG['allowed_usergroupsSTR'] .= "$user_group:";
            $stmt="INSERT INTO osdial_user_groups (user_group,group_name,allowed_campaigns) VALUES ('$user_group','$group_name','-ALL-CAMPAIGNS-');";
            $rslt=mysql_query($stmt, $link);

            echo "<br><b><font color=$default_text>USER GROUP ADDED: $user_group</font></b>\n";

            ### LOG CHANGES TO LOG FILE ###
            if ($WeBRooTWritablE > 0) {
                $fp = fopen ("./admin_changes_log.txt", "a");
                fwrite ($fp, "$date|ADD A NEW USER GROUP ENTRY     |$PHP_AUTH_USER|$ip|$stmt|\n");
                fclose($fp);
            }
        }
    }

    echo "</font>\n";
    $ADD=100000;
}


######################
# ADD=411111 modify user group info in the system
######################

if ($ADD==411111) {
    if ($LOG['modify_usergroups'] == 1) {
        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

        $preuser_group = $user_group;
        if ($LOG['multicomp'] > 0) $preuser_group = (($company_id * 1) + 100) . $user_group;

        if ($LOG['allowed_campaignsALL'] < 1) {
            echo "<br><font color=red>USER GROUP NOT MODIFIED - You may only view your User Group resources.</font><br>\n";
        } elseif ( (strlen($user_group) < 2) or (strlen($group_name) < 2) ) {
            echo "<br><font color=red>USER GROUP NOT MODIFIED - Please go back and look at the data you entered\n";
            echo "<br>Group name and description must be at least 2 characters in length</font><br>\n";
        } else {
            if ($LOG['multicomp'] > 0) $user_group = (($company_id * 1) + 100) . $user_group;

            if ($view_agent_realtime == 0) {
                $view_agent_realtime_iax_barge = 0;
                $view_agent_realtime_iax_listen = 0;
                $view_agent_realtime_sip_barge = 0;
                $view_agent_realtime_sip_listen = 0;
            }
            if ($view_agent_pause_summary == 0) $export_agent_pause_summary = 0;
            if ($view_agent_performance_detail == 0) $export_agent_performance_detail = 0;
            if ($view_agent_timesheet == 0) $export_agent_timesheet = 0;
            if ($view_ingroup_call_report == 0) $export_ingroup_call_report = 0;
            if ($view_campaign_call_report == 0) $export_campaign_call_report = 0;
            if ($view_campaign_recent_outbound_sales == 0) $export_campaign_recent_outbound_sales = 0;
            if ($view_lead_performance_campaign == 0) $export_lead_performance_campaign = 0;
            if ($view_lead_performance_list == 0) $export_lead_performance_list = 0;
            if ($view_lead_search_advanced == 0) $export_lead_search_advanced = 0;
            if ($view_list_cost_entry == 0) $export_list_cost_entry = 0;

            $stmt  = "UPDATE osdial_user_groups SET user_group='%s',group_name='%s',allowed_campaigns='%s',allowed_scripts='%s',allowed_email_templates='%s',";
            $stmt .= "view_agent_pause_summary='%s',export_agent_pause_summary='%s',view_agent_performance_detail='%s',export_agent_performance_detail='%s',";
            $stmt .= "view_agent_realtime='%s',view_agent_realtime_iax_barge='%s',view_agent_realtime_iax_listen='%s',view_agent_realtime_sip_barge='%s',view_agent_realtime_sip_listen='%s',view_agent_realtime_summary='%s',";
            $stmt .= "view_agent_stats='%s',view_agent_status='%s',view_agent_timesheet='%s',export_agent_timesheet='%s',view_campaign_call_report='%s',export_campaign_call_report='%s',";
            $stmt .= "view_campaign_recent_outbound_sales='%s',export_campaign_recent_outbound_sales='%s',view_ingroup_call_report='%s',export_ingroup_call_report='%s',";
            $stmt .= "view_lead_performance_campaign='%s',export_lead_performance_campaign='%s',view_lead_performance_list='%s',export_lead_performance_list='%s',";
            $stmt .= "view_lead_search='%s',view_lead_search_advanced='%s',export_lead_search_advanced='%s',view_list_cost_entry='%s',export_list_cost_entry='%s',";
            $stmt .= "view_server_performance='%s',view_server_times='%s',view_usergroup_hourly_stats='%s' ";
            $stmt .= "WHERE user_group='%s';";

            $scripts_value = ' ' . implode(' ', $scripts_values) . ' -';
            $emails_value = ' ' . implode(' ', $emails_values) . ' -';
            if (preg_match('/ -ALL-CAMPAIGNS- /',$campaigns_value)) $campaigns_value = ' -ALL-CAMPAIGNS- -';
            if (preg_match('/ -ALL-SCRIPTS- /',$scripts_value)) $scripts_value = ' -ALL-SCRIPTS- -';
            if (preg_match('/ -ALL-EMAIL-TEMPLATES- /',$emails_value)) $emails_value = ' -ALL-EMAIL-TEMPLATES- -';

            $stmt=sprintf($stmt,
                mres($user_group),mres($group_name),mres($campaigns_value),mres($scripts_value),mres($emails_value),
                mres($view_agent_pause_summary),mres($export_agent_pause_summary),mres($view_agent_performance_detail),mres($export_agent_performance_detail),
                mres($view_agent_realtime),mres($view_agent_realtime_iax_barge),mres($view_agent_realtime_iax_listen),mres($view_agent_realtime_sip_barge),mres($view_agent_realtime_sip_listen),mres($view_agent_realtime_summary),
                mres($view_agent_stats),mres($view_agent_status),mres($view_agent_timesheet),mres($export_agent_timesheet),mres($view_campaign_call_report),mres($export_campaign_call_report),
                mres($view_campaign_recent_outbound_sales),mres($export_campaign_recent_outbound_sales),mres($view_ingroup_call_report),mres($export_ingroup_call_report),
                mres($view_lead_performance_campaign),mres($export_lead_performance_campaign),mres($view_lead_performance_list),mres($export_lead_performance_list),
                mres($view_lead_search),mres($view_lead_search_advanced),mres($export_lead_search_advanced),mres($view_list_cost_entry),
                mres($export_list_cost_entry),mres($view_server_performance),mres($view_server_times),mres($view_usergroup_hourly_stats),
                mres($OLDuser_group));
            $rslt=mysql_query($stmt, $link);


            echo "<br><b><font color=$default_text>USER GROUP MODIFIED</font></b>\n";

            ### LOG CHANGES TO LOG FILE ###
            if ($WeBRooTWritablE > 0) {
                $fp = fopen ("./admin_changes_log.txt", "a");
                fwrite ($fp, "$date|MODIFY USER GROUP ENTRY     |$PHP_AUTH_USER|$ip|$stmt|\n");
                fclose($fp);
            }
        }
        echo "</font>\n";
        $ADD=311111;    # go to user group modification form below
    } else {
        echo "<font color=red>You do not have permission to view this page</font>\n";
    }
}

######################
# ADD=511111 confirmation before deletion of user group record
######################

if ($ADD==511111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    if ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT DELETED - You may only view your User Group resources.</font><br>\n";
    } elseif ( (strlen($user_group) < 2) or ($LOGdelete_user_groups < 1) ) {
        echo "<br><font color=red>USER GROUP NOT DELETED - Please go back and look at the data you entered\n";
        echo "<br>User_group be at least 2 characters in length</font><br>\n";
    } else {
        echo "<br><b><font color=$default_text>USER GROUP DELETION CONFIRMATION: $user_group</b>\n";
        echo "<br><br><a href=\"$PHP_SELF?ADD=611111&user_group=$user_group&CoNfIrM=YES\">Click here to delete user group $user_group</a></font><br><br><br>\n";
    }

    echo "</font>\n";
    $ADD='311111';        # go to user group modification below
}

######################
# ADD=611111 delete user group record
######################

if ($ADD==611111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    if ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT DELETED - You may only view your User Group resources.</font><br>\n";
    } elseif ( (strlen($user_group) < 2) or ($CoNfIrM != 'YES') or ($LOGdelete_user_groups < 1) ) {
        echo "<br><font color=red>USER GROUP NOT DELETED - Please go back and look at the data you entered\n";
        echo "<br>User_group be at least 2 characters in length</font><br>\n";
    } else {
        $stmt="DELETE FROM osdial_user_groups WHERE user_group='$user_group' LIMIT 1;";
        $rslt=mysql_query($stmt, $link);

        ### LOG CHANGES TO LOG FILE ###
        if ($WeBRooTWritablE > 0) {
            $fp = fopen ("./admin_changes_log.txt", "a");
            fwrite ($fp, "$date|!DELETING USRGROUP!!|$PHP_AUTH_USER|$ip|user_group='$user_group'|\n");
            fclose($fp);
        }
        echo "<br><b><font color=$default_text>USER GROUP DELETION COMPLETED: $user_group</font></b>\n";
        echo "<br><br>\n";
    }

    echo "</font>\n";
    $ADD='100000';        # go to user group list
}

######################
# ADD=311111 modify user group info in the system
######################

if ($ADD==311111) {
    if ($LOG['modify_usergroups'] == 1) {

        $stmt = sprintf("SELECT * FROM osdial_user_groups WHERE user_group IN %s AND user_group='%s';",$LOG['allowed_usergroupsSQL'],$user_group);
        $rslt=mysql_query($stmt, $link);
        $row=mysql_fetch_row($rslt);
        $user_group = $row[0];
        $group_name = $row[1];
        $view_agent_pause_summary = $row[3];
        $export_agent_pause_summary = $row[4];
        $view_agent_performance_detail = $row[5];
        $export_agent_performance_detail = $row[6];
        $view_agent_realtime = $row[7];
        $view_agent_realtime_iax_barge = $row[8];
        $view_agent_realtime_iax_listen = $row[9];
        $view_agent_realtime_sip_barge = $row[10];
        $view_agent_realtime_sip_listen = $row[11];
        $view_agent_realtime_summary = $row[12];
        $view_agent_stats = $row[13];
        $view_agent_status = $row[14];
        $view_agent_timesheet = $row[15];
        $export_agent_timesheet = $row[16];
        $view_campaign_call_report = $row[17];
        $export_campaign_call_report = $row[18];
        $view_campaign_recent_outbound_sales = $row[19];
        $export_campaign_recent_outbound_sales = $row[20];
        $view_ingroup_call_report = $row[21];
        $export_ingroup_call_report = $row[22];
        $view_lead_performance_campaign = $row[23];
        $export_lead_performance_campaign = $row[24];
        $view_lead_performance_list = $row[25];
        $export_lead_performance_list = $row[26];
        $view_lead_search = $row[27];
        $view_lead_search_advanced = $row[28];
        $export_lead_search_advanced = $row[29];
        $view_list_cost_entry = $row[30];
        $export_list_cost_entry = $row[31];
        $view_server_performance = $row[32];
        $view_server_times = $row[33];
        $view_usergroup_hourly_stats = $row[34];
        $allowed_scripts = $row[35];
        $allowed_email_templates = $row[36];

        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";
        echo "<center>\n";
        echo "  <br><font color=$default_text size=+1>MODIFY A USER GROUP</font><br><br>\n";
        echo "  <form action=$PHP_SELF method=POST>\n";
        echo "  <input type=hidden name=ADD value=411111>\n";
        echo "  <input type=hidden name=OLDuser_group value=\"$user_group\">\n";


        echo "  <table width=$section_width cellspacing=3>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td width=40% align=right>Group: </td>\n";
        echo "      <td align=left>\n";
        if ($LOG['multicomp_admin'] > 0) {
            $comps = get_krh($link, 'osdial_companies', '*','',"status IN ('ACTIVE','INACTIVE','SUSPENDED')",'');
            echo "        <select name=company_id>\n";
            foreach ($comps as $comp) {
                $csel = "";
                if ((substr($user_group,0,3) * 1 - 100) == $comp['id']) $csel = "selected";
                echo "          <option value=$comp[id] $csel>" . (($comp['id'] * 1) + 100) . ": " . $comp['name'] . "</option>\n";
            }
            echo "        </select>\n";
        } elseif ($LOG['multicomp']>0) {
            echo "        <input type=hidden name=company_id value=$LOG[company_id]>\n";
        }
        $mcug = $user_group;
        if ($LOG['multicomp']>0 and preg_match($LOG['companiesRE'],$user_group)) $mcug = substr($user_group,3);
        echo "        <input type=text name=user_group size=15 maxlength=20 value=\"$mcug\">\n";
        echo "        $NWB#osdial_user_groups-user_group$NWE\n";
        echo "      </td>\n";
        echo "    </tr>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td align=right>Description: </td>\n";
        echo "      <td align=left><input type=text name=group_name size=40 maxlength=40 value=\"$group_name\"> $NWB#osdial_user_groups-group_name$NWE</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
        echo "  </table>\n";



        ### Allowed Campaigns ###
        $ugcamps = explode("<BR>",$campaigns_list);
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Campaigns</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Campaign</td>\n";
        echo "    </tr>\n";
        $i=0;
        foreach ($ugcamps as $ugcamp) {
            $ugcsplit = explode('<label',$ugcamp);
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput>" . $ugcsplit[0] . "</td>\n";
            echo "      <td align=left>\n";
            if ($i==0) echo "        <b>\n";
            echo "        <label" . $ugcsplit[1] . "\n";
            if ($i==0) echo "        </b>\n";
            echo "      </td>\n";
            echo "    </tr>\n";
            $i++;
        }
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";
        echo "  </table>\n";

        ### Allowed scripts ###
        $scripts = get_krh($link, 'osdial_scripts', '*','',"active='Y'",'');
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Scripts</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Script</td>\n";
        echo "    </tr>\n";
        $sel = '';
        if (preg_match('/ -ALL-SCRIPTS- /',$allowed_scripts)) $sel='checked';
        echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
        echo "      <td align=center class=tabinput><input type=checkbox name=scripts_values[] id=scripts_values value=\"-ALL-SCRIPTS-\" $sel></td>\n";
        echo "      <td align=left><b><label for=scripts_values>ALL-SCRIPTS -</label></b></td>\n";
        echo "    </tr>\n";
        foreach ($scripts as $script) {
            $sel = '';
            if (preg_match('/ ' . $script['script_id'] . ' /',$allowed_scripts)) $sel='checked';
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput><input type=checkbox name=scripts_values[] id=scripts_values" . $script['script_id'] . " value=\"" . $script['script_id'] . "\" $sel></td>\n";
            echo "      <td align=left><label for=scripts_values" . $script['script_id'] . ">" . $script['script_id'] . ' - ' . $script['script_name'] . "</label></td>\n";
            echo "    </tr>\n";
        }
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";
        echo "  </table>\n";

        ### Allowed Email Templates ###
        $emails = get_krh($link, 'osdial_email_templates', '*','',"active='Y'",'');
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Email Templates</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Template</td>\n";
        echo "    </tr>\n";
        $sel = '';
        if (preg_match('/ -ALL-EMAIL-TEMPLATES- /',$allowed_email_templates)) $sel='checked';
        echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
        echo "      <td align=center class=tabinput><input type=checkbox name=emails_values[] id=emails_values value=\"-ALL-EMAIL-TEMPLATES-\" $sel></td>\n";
        echo "      <td align=left><b><label for=emails_values>ALL-EMAIL-TEMPLATES - </label></b></td>\n";
        echo "    </tr>\n";
        foreach ($emails as $email) {
            $sel = '';
            if (preg_match('/ ' . $email['et_id'] . ' /',$allowed_email_templates)) $sel='checked';
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput><input type=checkbox name=emails_values[] id=emails_values" . $email['et_id'] . " value=\"" . $email['et_name'] . "\" $sel></td>\n";
            echo "      <td align=left><label for=emails_values" . $email['et_id'] . ">" . $email['et_id'] . ' - ' . $email['et_name'] . "</label></td>\n";
            echo "    </tr>\n";
        }


        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";<commit_msg>Display Scripts/EmailTemplates in red if inactive.<commit_after><?php
#
# Copyright (C) 2008  <NAME> <<EMAIL>>      LICENSE: AGPLv2
# Copyright (C) 2009  <NAME>  <<EMAIL>>    LICENSE: AGPLv3
# Copyright (C) 2009  <NAME> <<EMAIL>>  LICENSE: AGPLv3
#
#     This file is part of OSDial.
#
#     OSDial is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of
#     the License, or (at your option) any later version.
#
#     OSDial is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public
#     License along with OSDial.  If not, see <http://www.gnu.org/licenses/>.
#


######################
# ADD=111111 display the ADD NEW AGENTS GROUP SCREEN
######################

if ($ADD==111111) {
    if ($LOG['modify_usergroups'] == 1 and $LOG['allowed_campaignsALL'] > 0) {
        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

        echo "<center>\n";
        echo "  <br><font color=$default_text size=+1>ADD NEW AGENTS GROUP</font><br><br>\n";
        echo "  <form action=$PHP_SELF method=POST>\n";
        echo "  <input type=hidden name=ADD value=211111>\n";
        echo "  <table width=$section_width cellspacing=3>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td width=40% align=right>Group: </td>\n";
        echo "      <td align=left>\n";
        if ($LOG['multicomp_admin'] > 0) {
            $comps = get_krh($link, 'osdial_companies', '*','',"status IN ('ACTIVE','INACTIVE','SUSPENDED')",'');
            echo "        <select name=company_id>\n";
            foreach ($comps as $comp) {
                echo "          <option value=$comp[id]>" . (($comp['id'] * 1) + 100) . ": " . $comp['name'] . "</option>\n";
            }
            echo "        </select>\n";
        } elseif ($LOG['multicomp']>0) {
            echo "        <input type=hidden name=company_id value=$LOG[company_id]>";
        }
        echo "        <input type=text name=user_group size=15 maxlength=20> $NWB#osdial_user_groups-user_group$NWE\n";
        echo "      </td>\n";
        echo "    </tr>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td align=right>Description: </td>\n";
        echo "      <td align=left><input type=text name=group_name size=40 maxlength=40> $NWB#osdial_user_groups-group_name$NWE</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
        echo "  </table>\n";
        echo "  </form>\n";
        echo "</center>\n";

        echo "</font>\n";
    } elseif ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT MODIFIED - You may only view your User Group resources.</font><br>\n";
    } else {
        echo "<font color=red>You do not have permission to view this page</font>\n";
    }
}


######################
# ADD=211111 adds new user group to the system
######################

if ($ADD==211111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    $preuser_group = $user_group;
    if ($LOG['multicomp'] > 0) $preuser_group = (($company_id * 1) + 100) . $user_group;
    $stmt="SELECT count(*) FROM osdial_user_groups WHERE user_group='$preuser_group';";
    $rslt=mysql_query($stmt, $link);
    $row=mysql_fetch_row($rslt);
    if ($row[0] > 0) {
        echo "<br><font color=red>USER GROUP NOT ADDED - there is already a user group entry with this name</font>\n";
    } else {
         if (strlen($user_group) < 2 or strlen($group_name) < 2) {
             echo "<br><font color=red>USER GROUP NOT ADDED - Please go back and look at the data you entered\n";
             echo "<br>Group name and description must be at least 2 characters in length</font><br>\n";
         } else {
            if ($LOG['multicomp'] > 0) $user_group = (($company_id * 1) + 100) . $user_group;
            $LOG['allowed_usergroupsSQL'] = rtrim($LOG['allowed_usergroupsSQL'],')');
            $LOG['allowed_usergroupsSQL'] .= ",'$user_group')";
            $LOG['allowed_usergroupsSTR'] .= "$user_group:";
            $stmt="INSERT INTO osdial_user_groups (user_group,group_name,allowed_campaigns) VALUES ('$user_group','$group_name','-ALL-CAMPAIGNS-');";
            $rslt=mysql_query($stmt, $link);

            echo "<br><b><font color=$default_text>USER GROUP ADDED: $user_group</font></b>\n";

            ### LOG CHANGES TO LOG FILE ###
            if ($WeBRooTWritablE > 0) {
                $fp = fopen ("./admin_changes_log.txt", "a");
                fwrite ($fp, "$date|ADD A NEW USER GROUP ENTRY     |$PHP_AUTH_USER|$ip|$stmt|\n");
                fclose($fp);
            }
        }
    }

    echo "</font>\n";
    $ADD=100000;
}


######################
# ADD=411111 modify user group info in the system
######################

if ($ADD==411111) {
    if ($LOG['modify_usergroups'] == 1) {
        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

        $preuser_group = $user_group;
        if ($LOG['multicomp'] > 0) $preuser_group = (($company_id * 1) + 100) . $user_group;

        if ($LOG['allowed_campaignsALL'] < 1) {
            echo "<br><font color=red>USER GROUP NOT MODIFIED - You may only view your User Group resources.</font><br>\n";
        } elseif ( (strlen($user_group) < 2) or (strlen($group_name) < 2) ) {
            echo "<br><font color=red>USER GROUP NOT MODIFIED - Please go back and look at the data you entered\n";
            echo "<br>Group name and description must be at least 2 characters in length</font><br>\n";
        } else {
            if ($LOG['multicomp'] > 0) $user_group = (($company_id * 1) + 100) . $user_group;

            if ($view_agent_realtime == 0) {
                $view_agent_realtime_iax_barge = 0;
                $view_agent_realtime_iax_listen = 0;
                $view_agent_realtime_sip_barge = 0;
                $view_agent_realtime_sip_listen = 0;
            }
            if ($view_agent_pause_summary == 0) $export_agent_pause_summary = 0;
            if ($view_agent_performance_detail == 0) $export_agent_performance_detail = 0;
            if ($view_agent_timesheet == 0) $export_agent_timesheet = 0;
            if ($view_ingroup_call_report == 0) $export_ingroup_call_report = 0;
            if ($view_campaign_call_report == 0) $export_campaign_call_report = 0;
            if ($view_campaign_recent_outbound_sales == 0) $export_campaign_recent_outbound_sales = 0;
            if ($view_lead_performance_campaign == 0) $export_lead_performance_campaign = 0;
            if ($view_lead_performance_list == 0) $export_lead_performance_list = 0;
            if ($view_lead_search_advanced == 0) $export_lead_search_advanced = 0;
            if ($view_list_cost_entry == 0) $export_list_cost_entry = 0;

            $stmt  = "UPDATE osdial_user_groups SET user_group='%s',group_name='%s',allowed_campaigns='%s',allowed_scripts='%s',allowed_email_templates='%s',";
            $stmt .= "view_agent_pause_summary='%s',export_agent_pause_summary='%s',view_agent_performance_detail='%s',export_agent_performance_detail='%s',";
            $stmt .= "view_agent_realtime='%s',view_agent_realtime_iax_barge='%s',view_agent_realtime_iax_listen='%s',view_agent_realtime_sip_barge='%s',view_agent_realtime_sip_listen='%s',view_agent_realtime_summary='%s',";
            $stmt .= "view_agent_stats='%s',view_agent_status='%s',view_agent_timesheet='%s',export_agent_timesheet='%s',view_campaign_call_report='%s',export_campaign_call_report='%s',";
            $stmt .= "view_campaign_recent_outbound_sales='%s',export_campaign_recent_outbound_sales='%s',view_ingroup_call_report='%s',export_ingroup_call_report='%s',";
            $stmt .= "view_lead_performance_campaign='%s',export_lead_performance_campaign='%s',view_lead_performance_list='%s',export_lead_performance_list='%s',";
            $stmt .= "view_lead_search='%s',view_lead_search_advanced='%s',export_lead_search_advanced='%s',view_list_cost_entry='%s',export_list_cost_entry='%s',";
            $stmt .= "view_server_performance='%s',view_server_times='%s',view_usergroup_hourly_stats='%s' ";
            $stmt .= "WHERE user_group='%s';";

            $scripts_value = ' ' . implode(' ', $scripts_values) . ' -';
            $emails_value = ' ' . implode(' ', $emails_values) . ' -';
            if (preg_match('/ -ALL-CAMPAIGNS- /',$campaigns_value)) $campaigns_value = ' -ALL-CAMPAIGNS- -';
            if (preg_match('/ -ALL-SCRIPTS- /',$scripts_value)) $scripts_value = ' -ALL-SCRIPTS- -';
            if (preg_match('/ -ALL-EMAIL-TEMPLATES- /',$emails_value)) $emails_value = ' -ALL-EMAIL-TEMPLATES- -';

            $stmt=sprintf($stmt,
                mres($user_group),mres($group_name),mres($campaigns_value),mres($scripts_value),mres($emails_value),
                mres($view_agent_pause_summary),mres($export_agent_pause_summary),mres($view_agent_performance_detail),mres($export_agent_performance_detail),
                mres($view_agent_realtime),mres($view_agent_realtime_iax_barge),mres($view_agent_realtime_iax_listen),mres($view_agent_realtime_sip_barge),mres($view_agent_realtime_sip_listen),mres($view_agent_realtime_summary),
                mres($view_agent_stats),mres($view_agent_status),mres($view_agent_timesheet),mres($export_agent_timesheet),mres($view_campaign_call_report),mres($export_campaign_call_report),
                mres($view_campaign_recent_outbound_sales),mres($export_campaign_recent_outbound_sales),mres($view_ingroup_call_report),mres($export_ingroup_call_report),
                mres($view_lead_performance_campaign),mres($export_lead_performance_campaign),mres($view_lead_performance_list),mres($export_lead_performance_list),
                mres($view_lead_search),mres($view_lead_search_advanced),mres($export_lead_search_advanced),mres($view_list_cost_entry),
                mres($export_list_cost_entry),mres($view_server_performance),mres($view_server_times),mres($view_usergroup_hourly_stats),
                mres($OLDuser_group));
            $rslt=mysql_query($stmt, $link);


            echo "<br><b><font color=$default_text>USER GROUP MODIFIED</font></b>\n";

            ### LOG CHANGES TO LOG FILE ###
            if ($WeBRooTWritablE > 0) {
                $fp = fopen ("./admin_changes_log.txt", "a");
                fwrite ($fp, "$date|MODIFY USER GROUP ENTRY     |$PHP_AUTH_USER|$ip|$stmt|\n");
                fclose($fp);
            }
        }
        echo "</font>\n";
        $ADD=311111;    # go to user group modification form below
    } else {
        echo "<font color=red>You do not have permission to view this page</font>\n";
    }
}

######################
# ADD=511111 confirmation before deletion of user group record
######################

if ($ADD==511111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    if ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT DELETED - You may only view your User Group resources.</font><br>\n";
    } elseif ( (strlen($user_group) < 2) or ($LOGdelete_user_groups < 1) ) {
        echo "<br><font color=red>USER GROUP NOT DELETED - Please go back and look at the data you entered\n";
        echo "<br>User_group be at least 2 characters in length</font><br>\n";
    } else {
        echo "<br><b><font color=$default_text>USER GROUP DELETION CONFIRMATION: $user_group</b>\n";
        echo "<br><br><a href=\"$PHP_SELF?ADD=611111&user_group=$user_group&CoNfIrM=YES\">Click here to delete user group $user_group</a></font><br><br><br>\n";
    }

    echo "</font>\n";
    $ADD='311111';        # go to user group modification below
}

######################
# ADD=611111 delete user group record
######################

if ($ADD==611111) {
    echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";

    if ($LOG['allowed_campaignsALL'] < 1) {
        echo "<br><font color=red>USER GROUP NOT DELETED - You may only view your User Group resources.</font><br>\n";
    } elseif ( (strlen($user_group) < 2) or ($CoNfIrM != 'YES') or ($LOGdelete_user_groups < 1) ) {
        echo "<br><font color=red>USER GROUP NOT DELETED - Please go back and look at the data you entered\n";
        echo "<br>User_group be at least 2 characters in length</font><br>\n";
    } else {
        $stmt="DELETE FROM osdial_user_groups WHERE user_group='$user_group' LIMIT 1;";
        $rslt=mysql_query($stmt, $link);

        ### LOG CHANGES TO LOG FILE ###
        if ($WeBRooTWritablE > 0) {
            $fp = fopen ("./admin_changes_log.txt", "a");
            fwrite ($fp, "$date|!DELETING USRGROUP!!|$PHP_AUTH_USER|$ip|user_group='$user_group'|\n");
            fclose($fp);
        }
        echo "<br><b><font color=$default_text>USER GROUP DELETION COMPLETED: $user_group</font></b>\n";
        echo "<br><br>\n";
    }

    echo "</font>\n";
    $ADD='100000';        # go to user group list
}

######################
# ADD=311111 modify user group info in the system
######################

if ($ADD==311111) {
    if ($LOG['modify_usergroups'] == 1) {

        $stmt = sprintf("SELECT * FROM osdial_user_groups WHERE user_group IN %s AND user_group='%s';",$LOG['allowed_usergroupsSQL'],$user_group);
        $rslt=mysql_query($stmt, $link);
        $row=mysql_fetch_row($rslt);
        $user_group = $row[0];
        $group_name = $row[1];
        $view_agent_pause_summary = $row[3];
        $export_agent_pause_summary = $row[4];
        $view_agent_performance_detail = $row[5];
        $export_agent_performance_detail = $row[6];
        $view_agent_realtime = $row[7];
        $view_agent_realtime_iax_barge = $row[8];
        $view_agent_realtime_iax_listen = $row[9];
        $view_agent_realtime_sip_barge = $row[10];
        $view_agent_realtime_sip_listen = $row[11];
        $view_agent_realtime_summary = $row[12];
        $view_agent_stats = $row[13];
        $view_agent_status = $row[14];
        $view_agent_timesheet = $row[15];
        $export_agent_timesheet = $row[16];
        $view_campaign_call_report = $row[17];
        $export_campaign_call_report = $row[18];
        $view_campaign_recent_outbound_sales = $row[19];
        $export_campaign_recent_outbound_sales = $row[20];
        $view_ingroup_call_report = $row[21];
        $export_ingroup_call_report = $row[22];
        $view_lead_performance_campaign = $row[23];
        $export_lead_performance_campaign = $row[24];
        $view_lead_performance_list = $row[25];
        $export_lead_performance_list = $row[26];
        $view_lead_search = $row[27];
        $view_lead_search_advanced = $row[28];
        $export_lead_search_advanced = $row[29];
        $view_list_cost_entry = $row[30];
        $export_list_cost_entry = $row[31];
        $view_server_performance = $row[32];
        $view_server_times = $row[33];
        $view_usergroup_hourly_stats = $row[34];
        $allowed_scripts = $row[35];
        $allowed_email_templates = $row[36];

        echo "<font face=\"Arial,Helvetica\" color=$default_text size=2>\n";
        echo "<center>\n";
        echo "  <br><font color=$default_text size=+1>MODIFY A USER GROUP</font><br><br>\n";
        echo "  <form action=$PHP_SELF method=POST>\n";
        echo "  <input type=hidden name=ADD value=411111>\n";
        echo "  <input type=hidden name=OLDuser_group value=\"$user_group\">\n";


        echo "  <table width=$section_width cellspacing=3>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td width=40% align=right>Group: </td>\n";
        echo "      <td align=left>\n";
        if ($LOG['multicomp_admin'] > 0) {
            $comps = get_krh($link, 'osdial_companies', '*','',"status IN ('ACTIVE','INACTIVE','SUSPENDED')",'');
            echo "        <select name=company_id>\n";
            foreach ($comps as $comp) {
                $csel = "";
                if ((substr($user_group,0,3) * 1 - 100) == $comp['id']) $csel = "selected";
                echo "          <option value=$comp[id] $csel>" . (($comp['id'] * 1) + 100) . ": " . $comp['name'] . "</option>\n";
            }
            echo "        </select>\n";
        } elseif ($LOG['multicomp']>0) {
            echo "        <input type=hidden name=company_id value=$LOG[company_id]>\n";
        }
        $mcug = $user_group;
        if ($LOG['multicomp']>0 and preg_match($LOG['companiesRE'],$user_group)) $mcug = substr($user_group,3);
        echo "        <input type=text name=user_group size=15 maxlength=20 value=\"$mcug\">\n";
        echo "        $NWB#osdial_user_groups-user_group$NWE\n";
        echo "      </td>\n";
        echo "    </tr>\n";
        echo "    <tr bgcolor=$oddrows>\n";
        echo "      <td align=right>Description: </td>\n";
        echo "      <td align=left><input type=text name=group_name size=40 maxlength=40 value=\"$group_name\"> $NWB#osdial_user_groups-group_name$NWE</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton><input type=submit name=SUBMIT value=SUBMIT></td></tr>\n";
        echo "  </table>\n";



        ### Allowed Campaigns ###
        $ugcamps = explode("<BR>",$campaigns_list);
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Campaigns</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Campaign</td>\n";
        echo "    </tr>\n";
        $i=0;
        foreach ($ugcamps as $ugcamp) {
            $ugcsplit = explode('<label',$ugcamp);
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput>" . $ugcsplit[0] . "</td>\n";
            echo "      <td align=left>\n";
            if ($i==0) echo "        <b>\n";
            echo "        <label" . $ugcsplit[1] . "\n";
            if ($i==0) echo "        </b>\n";
            echo "      </td>\n";
            echo "    </tr>\n";
            $i++;
        }
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";
        echo "  </table>\n";

        ### Allowed scripts ###
        $scripts = get_krh($link, 'osdial_scripts', '*','',"",'');
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Scripts</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Script</td>\n";
        echo "    </tr>\n";
        $sel = '';
        if (preg_match('/ -ALL-SCRIPTS- /',$allowed_scripts)) $sel='checked';
        echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
        echo "      <td align=center class=tabinput><input type=checkbox name=scripts_values[] id=scripts_values value=\"-ALL-SCRIPTS-\" $sel></td>\n";
        echo "      <td align=left><b><label for=scripts_values>ALL-SCRIPTS -</label></b></td>\n";
        echo "    </tr>\n";
        foreach ($scripts as $script) {
            $sel = '';
            if (preg_match('/ ' . $script['script_id'] . ' /',$allowed_scripts)) $sel='checked';
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput><input type=checkbox name=scripts_values[] id=scripts_values" . $script['script_id'] . " value=\"" . $script['script_id'] . "\" $sel></td>\n";
            $scstyle=''; if ($script['active']=='N') $scstyle=' style="color:#800000;"';
            echo "      <td align=left $scstyle><label for=scripts_values" . $script['script_id'] . ">" . $script['script_id'] . ' - ' . $script['script_name'] . "</label></td>\n";
            echo "    </tr>\n";
        }
        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";
        echo "  </table>\n";

        ### Allowed Email Templates ###
        $emails = get_krh($link, 'osdial_email_templates', '*','',"",'');
        echo "  <br>\n";
        echo "  <table bgcolor=grey width=50% cellspacing=1>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td align=center colspan=2>Allowed Email Templates</td>\n";
        echo "    </tr>\n";
        echo "    <tr class=tabheader>\n";
        echo "      <td></td>\n";
        echo "      <td align=left>Template</td>\n";
        echo "    </tr>\n";
        $sel = '';
        if (preg_match('/ -ALL-EMAIL-TEMPLATES- /',$allowed_email_templates)) $sel='checked';
        echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
        echo "      <td align=center class=tabinput><input type=checkbox name=emails_values[] id=emails_values value=\"-ALL-EMAIL-TEMPLATES-\" $sel></td>\n";
        echo "      <td align=left><b><label for=emails_values>ALL-EMAIL-TEMPLATES - </label></b></td>\n";
        echo "    </tr>\n";
        foreach ($emails as $email) {
            $sel = '';
            if (preg_match('/ ' . $email['et_id'] . ' /',$allowed_email_templates)) $sel='checked';
            echo "    <tr bgcolor=$oddrows class=\"row font1\">\n";
            echo "      <td align=center class=tabinput><input type=checkbox name=emails_values[] id=emails_values" . $email['et_id'] . " value=\"" . $email['et_name'] . "\" $sel></td>\n";
            $etstyle=''; if ($email['active']=='N') $etstyle=' style="color:#800000;"';
            echo "      <td align=left $etstyle><label for=emails_values" . $email['et_id'] . ">" . $email['et_id'] . ' - ' . $email['et_name'] . "</label></td>\n";
            echo "    </tr>\n";
        }


        echo "    <tr class=tabfooter><td align=center colspan=2 class=tabbutton nowrap><input type=submit name=SUBMIT value=SUBMIT>$NWB#osdial_user_groups-allowed_campaigns$NWE</td></tr>\n";
{'fraction_non_alphanumeric': 0.17532351628737172, 'fraction_numerical': 0.015484158857652834, 'mean_word_length': 2.879934210526316, 'pattern_counts': {'":': 4, '<': 565, '<?xml version=': 0, '>': 563, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397631', 'n_tokens_mistral': 15628, 'n_tokens_neox': 14658, 'n_words': 2838}