function paloSantoRG(&$pDB, $domain)
 {
     parent::__construct($pDB);
     if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) {
         $this->errMsg = "Invalid domain format";
     } else {
         $this->domain = $domain;
         $result = $this->getCodeByDomain($domain);
         if ($result == false) {
             $this->errMsg .= _tr("Can't create a new instace of paloQueuePBX") . $this->errMsg;
         } else {
             $this->code = $result["code"];
         }
     }
 }
 function paloSantoMoH(&$pDB, $domain)
 {
     parent::__construct($pDB);
     $this->_mohdir = '/var/lib/asterisk/moh/';
     // TODO: leer de musiconhold.conf
     if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) {
         // $this->errMsg="Invalid domain format";
     } else {
         $this->domain = $domain;
         $result = $this->getCodeByDomain($domain);
         if ($result == false) {
             $this->errMsg .= _tr("Can't create a new instace of paloQueuePBX") . $this->errMsg;
         } else {
             $this->code = $result["code"];
         }
     }
 }
 function paloDidPBX(&$pDB)
 {
     // Se recibe como parámetro una referencia a una conexión paloDB
     parent::__construct($pDB);
 }
 function getMonitoring($arrProp)
 {
     global $arrConf;
     $pPBX = new paloAsteriskDB($arrConf['elastix_dsn']["elastix"]);
     $where = array();
     $arrParam = null;
     $query = "SELECT calldate,src,dst,userfield,duration,organization_domain,fromout,toout,uniqueid FROM cdr WHERE userfield REGEXP '^audio:.+\$' ";
     //organization
     if (isset($arrProp['domain'])) {
         if ($arrProp['domain'] != 'all' && $arrProp['domain'] != '') {
             $where[] = " organization_domain=? ";
             $arrParam[] = $arrProp['domain'];
         }
     }
     //date
     if (empty($arrProp['date_start'])) {
         $start = date('Y-m-d') . " 00:00:00";
     } else {
         $start = date('Y-m-d', strtotime($arrProp["date_start"])) . " 00:00:00";
     }
     if (empty($arrProp['date_end'])) {
         $end = date('Y-m-d') . " 23:59:59";
     } else {
         $end = date('Y-m-d', strtotime($arrProp["date_end"])) . " 23:59:59";
     }
     $where[] = " (calldate >= ? AND calldate <= ?)";
     $arrParam[] = $start;
     $arrParam[] = $end;
     //type
     if (!empty($arrProp['type'])) {
         if ($arrProp['type'] == 'group') {
             //nombre de la grabacion
             $where[] = " userfield REGEXP '^audio:/var/spool/asterisk/monitor/.+/g.+\$' ";
         } elseif ($arrProp['type'] == 'queue') {
             //nombre de la grabacion
             $where[] = " userfield REGEXP '^audio:/var/spool/asterisk/monitor/.+/q.+\$' ";
         } elseif ($arrProp['type'] == 'conference') {
             //nombre de la grabacion
             $where[] = " userfield REGEXP '^audio:/var/spool/asterisk/monitor/.+/meetme-conf.+\$' ";
         } elseif ($arrProp['type'] == 'incoming') {
             $where[] = " toout=1 ";
         } elseif ($arrProp['type'] == 'outgoing') {
             $where[] = " fromout=1 ";
         }
     }
     if (isset($arrProp['source'])) {
         if ($arrProp['source'] != "") {
             $expression = $pPBX->getRegexPatternFromAsteriskPattern($arrProp['source']);
             if ($expression != false) {
                 $where[] = " src REGEXP ? ";
                 $arrParam[] = "^{$expression}\$";
             }
         }
     }
     if (isset($arrProp['destination'])) {
         if ($arrProp['destination'] != "") {
             $expression = $pPBX->getRegexPatternFromAsteriskPattern($arrProp['destination']);
             if ($expression != false) {
                 $where[] = " dst REGEXP ? ";
                 $arrParam[] = "^{$expression}\$";
             }
         }
     }
     if (count($where) > 0) {
         $query .= " AND " . implode(" AND ", $where);
     }
     if (isset($arrProp['limit']) && isset($arrProp['offset'])) {
         $query .= " limit ? offset ?";
         $arrParam[] = $arrProp['limit'];
         $arrParam[] = $arrProp['offset'];
     }
     $result = $this->_DB->fetchTable($query, TRUE, $arrParam);
     if ($result === false) {
         $this->errMsg = $this->_DB->errMsg;
         return false;
     } else {
         return $result;
     }
 }
    private function _construirWhereCDR($param)
    {
        global $arrConf;
        $pPBX = new paloAsteriskDB($arrConf['elastix_dsn']["elastix"]);
        $condSQL = array();
        $paramSQL = array();
        if (!is_array($param)) {
            $this->errMsg = '(internal) invalid parameter array';
            return NULL;
        }
        if (!function_exists('_not_empty_param')) {
            function _not_empty_param($x)
            {
                if (is_null($x) || $x == '') {
                    return false;
                } else {
                    return true;
                }
            }
        }
        $param = array_filter($param, '_not_empty_param');
        if (isset($param['organization'])) {
            if ($param['organization'] != 'all') {
                $condSQL[] = 'cdr.organization_domain = ?';
                $paramSQL[] = $param['organization'];
            }
        }
        // Fecha y hora de inicio y final del rango
        if (isset($param['date_start'])) {
            $start = date('Y-m-d', strtotime($param['date_start'])) . " 00:00:00";
            $condSQL[] = 'calldate >= ?';
            $paramSQL[] = $start;
        }
        if (isset($param['date_end'])) {
            $end = date('Y-m-d', strtotime($param['date_end'])) . " 23:59:59";
            $condSQL[] = 'calldate <= ?';
            $paramSQL[] = $end;
        }
        // Estado de la llamada
        if (isset($param['status'])) {
            if ($param['status'] != 'all') {
                $condSQL[] = 'disposition = ?';
                $paramSQL[] = $param['status'];
            }
        }
        if (isset($param['calltype'])) {
            if (in_array($param['calltype'], array('incoming', 'outgoing'))) {
                $sCampo = $param['calltype'] == 'incoming' ? 'fromout' : 'toout';
                $condSQL[] = "{$sCampo} = 1";
            }
        }
        //permite busque por patron de marcado por lo que ahi que traducir
        //estos patrones al formato de busqueda aceptado por mysql
        //en el caso de src a dst tambien se hace la busqueda en channel y dstchannel respectivament
        if (isset($param['src'])) {
            $expression = $pPBX->getRegexPatternFromAsteriskPattern($param['src']);
            if ($expression != false) {
                $condSQL[] = "( src REGEXP ? OR SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'_',-1) REGEXP ?)";
                $paramSQL[] = "^{$expression}\$";
                $paramSQL[] = "^{$expression}\$";
            }
        }
        if (isset($param['dst'])) {
            $expression = $pPBX->getRegexPatternFromAsteriskPattern($param['dst']);
            if ($expression != false) {
                $condSQL[] = "( dst REGEXP ? OR SUBSTRING_INDEX(SUBSTRING_INDEX(dstchannel,'-',1),'_',-1) REGEXP ?)";
                $paramSQL[] = "^{$expression}\$";
                $paramSQL[] = "^{$expression}\$";
            }
        }
        if (isset($param['src_channel'])) {
            $condSQL[] = 'channel like ?';
            $paramSQL[] = "%" . $param['src_channel'] . "%";
        }
        if (isset($param['dst_channel'])) {
            $condSQL[] = 'dstchannel like ?';
            $paramSQL[] = "%" . $param['dst_channel'] . "%";
        }
        if (isset($param['accountcode'])) {
            $condSQL[] = 'accountcode LIKE ?';
            $paramSQL[] = $param['accountcode'];
        }
        // Extensión de fuente o destino
        // este parametro se usa para consultar regitro de un usuario
        // que solo puede ver sus registros
        if (isset($param['extension'])) {
            $condSQL[] = <<<SQL_COND_EXTENSION
(
       src = ?
    OR dst = ?
    OR SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'_',-1) = ?
    OR SUBSTRING_INDEX(SUBSTRING_INDEX(dstchannel,'-',1),'_',-1) = ?
)
SQL_COND_EXTENSION;
            array_push($paramSQL, $param['extension'], $param['extension'], $param['extension'], $param['extension']);
        }
        // Construir fragmento completo de sentencia SQL
        $where = array(implode(' AND ', $condSQL), $paramSQL);
        if ($where[0] != '') {
            $where[0] = 'WHERE ' . $where[0];
        }
        return $where;
    }
 function paloGeneralPBX(&$pDB)
 {
     parent::__construct($pDB);
 }
 function paloSantoRecordings(&$pDB)
 {
     parent::__construct($pDB);
 }
 function getExtensions($domain = null, $extension = null, $limit = null, $offset = null)
 {
     $where = array();
     $arrParam = null;
     $query = "SELECT * from extension";
     if (isset($domain) && $domain != 'all') {
         $where[] = " organization_domain=?";
         $arrParam[] = $domain;
     }
     if (isset($extension) && $extension != '') {
         $pPBX = new paloAsteriskDB($this->_DB);
         $expression = $pPBX->getRegexPatternFromAsteriskPattern($extension);
         if ($expression != false) {
             $where[] = " exten REGEXP ? ";
             $arrParam[] = "^{$expression}\$";
         }
     }
     if (count($where) > 0) {
         $query .= " WHERE " . implode(" AND ", $where);
     }
     $query .= " order by cast(exten as UNSIGNED) asc ";
     if (isset($limit) && isset($offset)) {
         $query .= " limit ? offset ?";
         $arrParam[] = $limit;
         $arrParam[] = $offset;
     }
     $result = $this->_DB->fetchTable($query, true, $arrParam);
     if ($result === false) {
         $this->errMsg = $this->_DB->errMsg;
         return false;
     } else {
         return $result;
     }
 }
Example #9
0
function reportExten($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    global $arrPermission;
    $pExten = new paloSantoExtensions($pDB);
    $pORGZ = new paloSantoOrganization($pDB);
    $error = '';
    $domain = getParameter("organization");
    $domain = empty($domain) ? 'all' : $domain;
    if ($credentials['userlevel'] != "superadmin") {
        $domain = $credentials['domain'];
    }
    $extension = getParameter("extension");
    if (isset($extension) && $extension != '') {
        $pPBX = new paloAsteriskDB($pDB);
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($extension);
        if ($expression === false) {
            $extension = '';
        }
    }
    $url['menu'] = $module_name;
    $url['organization'] = $domain;
    $url['extension'] = $extension;
    $total = $pExten->getNumExtensions($domain, $extension);
    $arrOrgz = array();
    if ($credentials['userlevel'] == "superadmin") {
        $arrOrgz = array("all" => _tr("all"));
        foreach ($pORGZ->getOrganization(array()) as $value) {
            $arrOrgz[$value["domain"]] = $value["name"];
        }
    }
    if ($total === false) {
        $error = $pExten->errMsg;
        $total = 0;
    }
    $limit = 20;
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    $oGrid->setTitle(_tr('Extensions List'));
    //$oGrid->setIcon('url de la imagen');
    $oGrid->setWidth("99%");
    $oGrid->setStart($total == 0 ? 0 : $offset + 1);
    $oGrid->setEnd($end);
    $oGrid->setTotal($total);
    $oGrid->setURL($url);
    if ($credentials['userlevel'] == "superadmin") {
        $arrColum[] = _tr("Organization");
    }
    $arrColum[] = _tr("Extension");
    $arrColum[] = _tr("Caller ID");
    $arrColum[] = _tr("Technology");
    $arrColum[] = _tr("Device");
    $arrColum[] = _tr("Context");
    $arrColum[] = _tr("User");
    $arrColum[] = _tr("Voicemail");
    $arrColum[] = _tr("Recording In") . " / " . _tr("Recording Out");
    $oGrid->setColumns($arrColum);
    $arrExtens = array();
    $arrData = array();
    if ($total != 0) {
        $arrExtens = $pExten->getExtensions($domain, $extension, $limit, $offset);
    }
    if ($arrExtens === false) {
        $error = _tr("Error to obtain extensions") . $pExten->errMsg;
        $arrExtens = array();
    } else {
        foreach ($arrExtens as $exten) {
            $arrTmp = array();
            if ($credentials['userlevel'] == "superadmin") {
                $arrTmp[] = $arrOrgz[$exten["organization_domain"]];
            }
            $arrTmp[] = "&nbsp;<a href='?menu=extensions&action=view&id_exten=" . $exten['id'] . "&organization={$exten['organization_domain']}'>" . $exten["exten"] . "</a>";
            $arrTmp[] = $exten['clid_name'] . " <{$exten['clid_number']}>";
            $arrTmp[] = strtoupper($exten['tech']);
            $arrTmp[] = $exten['device'];
            $arrTmp[] = $exten['context'];
            $query = "Select username from acl_user where extension=? and id_group in (select g.id from acl_group g join organization o on g.id_organization=o.id where o.domain=?)";
            $result = $pDB->getFirstRowQuery($query, false, array($exten["exten"], $exten["organization_domain"]));
            if ($result != false) {
                $arrTmp[] = $result[0];
            } else {
                $arrTmp[] = _tr("Nobody");
            }
            if (isset($exten["voicemail"])) {
                if ($exten["voicemail"] != "novm") {
                    $arrTmp[] = "yes";
                } else {
                    $arrTmp[] = "no";
                }
            } else {
                $arrTmp[] = "no";
            }
            $arrTmp[] = _tr($exten["record_in"]) . " / " . _tr($exten["record_out"]);
            $arrData[] = $arrTmp;
        }
    }
    $smarty->assign("USERLEVEL", $credentials['userlevel']);
    $smarty->assign("SEARCH", "<input type='submit' class='button' value='" . _tr('Search') . "' name='report'>");
    if ($pORGZ->getNumOrganization(array()) >= 1) {
        if (in_array('create', $arrPermission)) {
            if ($credentials['userlevel'] == 'superadmin') {
                $oGrid->addComboAction("organization_add", _tr("Create New Extension"), array_slice($arrOrgz, 1), $selected = null, "create_exten", $onchange_select = null);
            } else {
                $oGrid->addNew("create_exten", _tr("Create New Extension"));
            }
        }
        if ($credentials['userlevel'] == 'superadmin') {
            $_POST["organization"] = $domain;
            $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$domain], $_POST, array("organization" => "all"), true);
        }
        $_POST["extension"] = $extension;
        // patter to filter estension number
        $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Extension") . " = " . $extension, $_POST, array("extension" => ""));
        $arrFormElements = createFieldFilter($arrOrgz);
        $oFilterForm = new paloForm($smarty, $arrFormElements);
        $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST);
        $oGrid->showFilter(trim($htmlFilter));
    } else {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("It's necesary you create at least one organization so you can use this module"));
    }
    if ($error != "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", $error);
    }
    $contenidoModulo = $oGrid->fetchGrid(array(), $arrData);
    $mensaje = showMessageReload($module_name, $pDB, $credentials);
    $contenidoModulo = $mensaje . $contenidoModulo;
    return $contenidoModulo;
}
 function paloVoicemail(&$pDB)
 {
     parent::__construct($pDB);
 }
Example #11
0
function reportMonitoring($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    global $arrPermission;
    $error = '';
    $pMonitoring = new paloSantoMonitoring($pDB);
    $pORGZ = new paloSantoOrganization($arrConf['elastix_dsn']["elastix"]);
    $pPBX = new paloAsteriskDB($arrConf['elastix_dsn']["elastix"]);
    if ($credentials['userlevel'] == 'superadmin') {
        $domain = getParameter('organization');
        $domain = empty($domain) ? 'all' : $domain;
        $arrOrgz = array("all" => _tr("all"));
        foreach ($pORGZ->getOrganization(array()) as $value) {
            $arrOrgz[$value["domain"]] = $value["name"];
        }
    } else {
        $arrOrgz = array();
        $domain = $credentials['domain'];
    }
    $date_start = getParameter('date_start');
    if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_start)) {
        $date_start = date("d M Y");
    }
    $date_end = getParameter('date_end');
    if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_end)) {
        $date_end = date("d M Y");
    }
    $arrType = array("" => "", "conference" => _tr("Conference"), "group" => _tr("Group"), "queue" => _tr("Queue"), 'incoming' => _tr('Incoming'), 'outgoing' => _tr("Outgoing"));
    $type = getParameter("type");
    $type = array_key_exists($type, $arrType) ? $type : "";
    $source = getParameter("source");
    if (isset($source) && $source != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($source);
        if ($expression === false) {
            $source = '';
        }
    }
    $destination = getParameter("destination");
    if (isset($destination) && $destination != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($destination);
        if ($expression === false) {
            $destination = '';
        }
    }
    $url['menu'] = $module_name;
    $url['organization'] = $arrProp['organization'] = $domain;
    $url['date_start'] = $arrProp['date_start'] = $date_start;
    $url['date_end'] = $arrProp['date_end'] = $date_end;
    $url['source'] = $arrProp['source'] = $source;
    $url['destination'] = $arrProp['destination'] = $destination;
    $url['type'] = $arrProp['type'] = $type;
    //permission
    $delete = in_array("delete", $arrPermission);
    $export = in_array("export", $arrPermission);
    //begin grid parameters
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setTitle(_tr("Monitoring"));
    $oGrid->setIcon("web/apps/{$module_name}/images/pbx_monitoring.png");
    $oGrid->pagingShow(true);
    // show paging section.
    if ($export) {
        $oGrid->enableExport();
    }
    // enable export.
    $oGrid->setNameFile_Export(_tr("Monitoring"));
    $oGrid->setURL($url);
    if ($delete && !$oGrid->isExportAction()) {
        $arrColumns[] = "";
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $arrColumns[] = _tr('organization');
    }
    $arrColumns[] = _tr("Date");
    $arrColumns[] = _tr("Time");
    $arrColumns[] = _tr("Source");
    $arrColumns[] = _tr("Destination");
    $arrColumns[] = _tr("Duration");
    $arrColumns[] = _tr("Type");
    $arrColumns[] = _tr("File");
    if (!$oGrid->isExportAction()) {
        $arrColumns[] = "";
        //to display audio
    }
    $oGrid->setColumns($arrColumns);
    $totalMonitoring = $pMonitoring->getNumMonitoring($arrProp);
    if ($totalMonitoring === false) {
        $error = _tr('Recordings could not be retrieved.') . " " . "DATABASE ERROR";
        $totalMonitoring = 0;
    }
    $arrData = array();
    $arrResult = array();
    if ($totalMonitoring != 0) {
        if ($oGrid->isExportAction()) {
            $arrResult = $pMonitoring->getMonitoring($arrProp);
        } else {
            $limit = 20;
            $total = $totalMonitoring;
            $oGrid->setLimit($limit);
            $oGrid->setTotal($total);
            $offset = $oGrid->calculateOffset();
            $arrProp['limit'] = $limit;
            $arrProp['offset'] = $offset;
            $arrResult = $pMonitoring->getMonitoring($arrProp);
        }
    }
    if ($arrResult === false) {
        $error = _tr('Recordings could not be retrieved.') . " " . "DATABASE ERROR";
    } else {
        if ($oGrid->isExportAction()) {
            if (!$export) {
                $arrData = _tr('INVALID ACTION');
            }
            foreach ($arrResult as $monitoring) {
                $arrTmp = array();
                if ($credentials['userlevel'] == 'superadmin') {
                    $arrTmp[] = isset($arrOrgz[$monitoring['organization_domain']]) ? $arrOrgz[$monitoring['organization_domain']] : '';
                }
                $arrTmp[] = date('d M Y', strtotime($monitoring['calldate']));
                //date
                $arrTmp[] = date('H:i:s', strtotime($monitoring['calldate']));
                //time
                $arrTmp[] = $monitoring['src'];
                //source
                $arrTmp[] = $monitoring['dst'];
                //destination
                $arrTmp[] = SecToHHMMSS($monitoring['duration']);
                //duration
                $namefile = basename($monitoring['userfield']);
                $namefile = str_replace("audio:", "", $namefile);
                if ($monitoring['toout'] == '1') {
                    $arrTmp[] = $arrType['outgoing'];
                } elseif ($monitoring['fromout'] == '1') {
                    $arrTmp[] = $arrType['incoming'];
                } else {
                    if ($namefile[0] == 'g') {
                        $arrTmp[] = $arrType['group'];
                    } elseif ($namefile[0] == 'q') {
                        $arrTmp[] = $arrType['queue'];
                    } elseif (strpos($namefile, "meetme-conf") !== false) {
                        $arrTmp[] = $arrType['conference'];
                    } else {
                        $arrTmp[] = "";
                    }
                }
                $arrTmp[] = $namefile;
                $arrData[] = $arrTmp;
            }
        } else {
            $i = 0;
            foreach ($arrResult as $monitoring) {
                $arrTmp = array();
                if ($delete) {
                    $arrTmp[] = "<input type='checkbox' name='recordDel[]' value='{$monitoring['uniqueid']}' />";
                }
                if ($credentials['userlevel'] == 'superadmin') {
                    $arrTmp[] = isset($arrOrgz[$monitoring['organization_domain']]) ? $arrOrgz[$monitoring['organization_domain']] : '';
                }
                $arrTmp[] = date('d M Y', strtotime($monitoring['calldate']));
                //date
                $arrTmp[] = date('H:i:s', strtotime($monitoring['calldate']));
                //time
                $arrTmp[] = $monitoring['src'];
                //source
                $arrTmp[] = $monitoring['dst'];
                //destination
                $arrTmp[] = SecToHHMMSS($monitoring['duration']);
                //duration
                $namefile = basename($monitoring['userfield']);
                $namefile = str_replace("audio:", "", $namefile);
                if ($monitoring['toout'] == '1') {
                    $arrTmp[] = $arrType['outgoing'];
                } elseif ($monitoring['fromout'] == '1') {
                    $arrTmp[] = $arrType['incoming'];
                } else {
                    if ($namefile[0] == 'g') {
                        $arrTmp[] = $arrType['group'];
                    } elseif ($namefile[0] == 'q') {
                        $arrTmp[] = $arrType['queue'];
                    } elseif (strpos($namefile, "meetme-conf") !== false) {
                        $arrTmp[] = $arrType['conference'];
                    } else {
                        $arrTmp[] = "";
                    }
                }
                if ($namefile == 'deleted') {
                    $arrTmp[] = $namefile;
                    $arrTmp[] = "";
                } else {
                    $explod_name = explode(".", $namefile);
                    $ext = array_pop($explod_name);
                    if ($ext == 'gsm' || $ext == 'WAV') {
                        $div_display = "<a href=\"javascript:popUp('index.php?menu={$module_name}&action=display_record&id={$monitoring['uniqueid']}&rawmode=yes',350,100)\"><img style='cursor:pointer;' width='13px' src='web/apps/recordings/images/sound.png'/></a>  ";
                    } else {
                        $div_display = "<div class='single' id='{$i}' style='display:inline;'><span data-src='index.php?menu={$module_name}&action=download&id={$monitoring['uniqueid']}&rawmode=yes'><img style='cursor:pointer;' width='13px' src='web/apps/recordings/images/sound.png'/>&nbsp;&nbsp;</span></div>";
                    }
                    $download = "<a href='index.php?menu={$module_name}&action=download&id={$monitoring['uniqueid']}&rawmode=yes'>" . $namefile . "</a>";
                    $arrTmp[] = $div_display . $download;
                    $arrTmp[] = "<audio></audio>";
                }
                $i++;
                $arrData[] = $arrTmp;
            }
        }
    }
    $oGrid->setData($arrData);
    if ($error != "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", $error);
    }
    //begin section filter
    $smarty->assign("USERLEVEL", $credentials['userlevel']);
    $smarty->assign("SEARCH", "<input type='submit' class='button' value='" . _tr('Search') . "' name='report'>");
    if ($delete) {
        $oGrid->deleteList(_tr("Are you sure you want to delete?"), "delete", _tr("Delete Selected"), false);
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $_POST["organization"] = $domain;
        $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$domain], $_POST, array("organization" => _tr("all")), true);
    }
    $_POST['date_start'] = $arrProp['date_start'];
    $_POST['date_end'] = $arrProp['date_end'];
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Start Date") . " = " . $arrProp['date_start'] . ", " . _tr("End Date") . " = " . $arrProp['date_end'], $arrProp, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true);
    //DATE START - DATE END
    $_POST["type"] = $type;
    // type
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Type") . " = " . $arrType[$type], $_POST, array("type" => ""));
    $_POST["source"] = $source;
    // source
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source") . " = " . $source, $_POST, array("source" => ""));
    $_POST["destination"] = $destination;
    // destination
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination") . " = " . $source, $_POST, array("destination" => ""));
    $arrForm = createFieldFilter($arrOrgz, $arrType);
    $oFilterForm = new paloForm($smarty, $arrForm);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST);
    $oGrid->showFilter(trim($htmlFilter));
    //end section filter
    $content = $oGrid->fetchGrid();
    return $content;
}
 function paloSantoTrunk(&$pDB)
 {
     parent::__construct($pDB);
 }
Example #13
0
function reportCDR($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    global $arrPermission;
    $error = '';
    $pCDR = new paloSantoCDR($pDB);
    $pORGZ = new paloSantoOrganization($arrConf['elastix_dsn']["elastix"]);
    $pPBX = new paloAsteriskDB($arrConf['elastix_dsn']["elastix"]);
    if ($credentials['userlevel'] == 'superadmin') {
        $domain = getParameter('organization');
        $domain = empty($domain) ? 'all' : $domain;
        $arrOrgz = array("all" => _tr("all"));
        foreach ($pORGZ->getOrganization(array()) as $value) {
            $arrOrgz[$value["domain"]] = $value["name"];
        }
    } else {
        $arrOrgz = array();
        $domain = $credentials['domain'];
    }
    $date_start = getParameter('date_start');
    if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_start)) {
        $date_start = date("d M Y");
    }
    $date_end = getParameter('date_end');
    if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_end)) {
        $date_end = date("d M Y");
    }
    $src = getParameter("src");
    if (isset($src) && $src != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($src);
        if ($expression === false) {
            $src = '';
        }
    }
    $dst = getParameter("dst");
    if (isset($dst) && $dst != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($dst);
        if ($expression === false) {
            $dst = '';
        }
    }
    $src_channel = getParameter("src_channel");
    $dst_channel = getParameter("dst_channel");
    $calltype = getParameter("calltype");
    $arrCallType = array("all" => _tr("ALL"), 'incoming' => _tr('Incoming'), 'outgoing' => _tr("Outgoing"));
    $calltype = array_key_exists($calltype, $arrCallType) ? $calltype : "all";
    $status = getParameter("status");
    $arrStatus = array("all" => _tr("ALL"), 'ANSWERED' => _tr('ANSWERED'), 'BUSY' => _tr("BUSY"), 'FAILED' => _tr("FAILED"), "NO ANSWER " => _tr("NO ANSWER"));
    $status = array_key_exists($status, $arrStatus) ? $status : "all";
    $accountcode = getParameter('accountcode');
    $url['menu'] = $module_name;
    $url['organization'] = $paramFiltro['organization'] = $domain;
    $url['date_start'] = $paramFiltro['date_start'] = $date_start;
    $url['date_end'] = $paramFiltro['date_end'] = $date_end;
    $url['src'] = $paramFiltro['src'] = $src;
    $url['dst'] = $paramFiltro['dst'] = $dst;
    $url['src_channel'] = $paramFiltro['src_channel'] = $src_channel;
    $url['dst_channel'] = $paramFiltro['dst_channel'] = $dst_channel;
    $url['calltype'] = $paramFiltro['calltype'] = $calltype;
    $url['status'] = $paramFiltro['status'] = $status;
    $url['accountcode'] = $paramFiltro['accountcode'] = $accountcode;
    //permission
    $delete = in_array("delete", $arrPermission);
    $export = in_array("export", $arrPermission);
    //begin grid parameters
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setTitle(_tr("CDR Report"));
    $oGrid->pagingShow(true);
    if ($export) {
        $oGrid->enableExport();
        // enable export.
        $oGrid->setNameFile_Export(_tr("CDRReport"));
    }
    $oGrid->setURL($url);
    if ($delete && !$oGrid->isExportAction()) {
        $arrColumns[] = "<input type='checkbox' name='cdrcheckall' class='cdrcheckall' id='cdrcheckall' onclick='jqCheckAll(this.id)';>";
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $arrColumns[] = _tr("Organization");
    }
    $arrColumns[] = _tr("Date");
    $arrColumns[] = _tr("Source");
    if ($credentials['userlevel'] != 'superadmin') {
        $arrColumns[] = _tr("Ring Group");
    }
    $arrColumns[] = _tr("Destination");
    $arrColumns[] = _tr("Src. Channel");
    $arrColumns[] = _tr("Account Code");
    $arrColumns[] = _tr("Dst. Channel");
    $arrColumns[] = _tr("Call Direction");
    $arrColumns[] = _tr("Status");
    $arrColumns[] = _tr("Duration");
    $oGrid->setColumns($arrColumns);
    //get NumCDR
    $total = $pCDR->getNumCDR($paramFiltro);
    if ($total === false) {
        $total = 0;
        $error = _tr("An error has ocurred to retrieve CDR data") . " " . "DATABASE ERROR";
    }
    $arrData = array();
    $arrResult = array();
    if ($total != 0) {
        if ($oGrid->isExportAction()) {
            if (!$export) {
                $arrData = _tr('INVALID ACTION');
            } else {
                $arrResult = $pCDR->listarCDRs($paramFiltro);
            }
        } else {
            $limit = 20;
            $oGrid->setLimit($limit);
            $oGrid->setTotal($total);
            $offset = $oGrid->calculateOffset();
            $arrResult = $pCDR->listarCDRs($paramFiltro, $limit, $offset);
        }
    }
    if ($arrResult === false) {
        $error = _tr('CDR data could not be retrieved.') . " " . "DATABASE ERROR";
    } else {
        foreach ($arrResult as $value) {
            $arrTmp = array();
            if ($delete && !$oGrid->isExportAction()) {
                $arrTmp[] = "<input type='checkbox' name='crdDel[]' class='cdrdelete' value='{$value['6']}' />";
            }
            if ($credentials['userlevel'] == "superadmin") {
                $arrTmp[] = isset($arrOrgz[$value[11]]) ? $arrOrgz[$value[11]] : '';
            }
            $arrTmp[] = $value[0];
            //calldate
            $arrTmp[] = $value[1];
            //src
            if ($credentials['userlevel'] != "superadmin") {
                $arrTmp[] = $value[10];
            }
            //rg_name
            $arrTmp[] = $value[2];
            //dst
            $arrTmp[] = $value[3];
            //channel
            $arrTmp[] = $value[9];
            //accountcode
            $arrTmp[] = $value[4];
            //dst_channel
            if ($value[12] == "1" || $value[13] == "1") {
                //call_type
                $arrTmp[] = $value[12] == "1" ? "outgoing" : "incoming";
            } else {
                $arrTmp[] = "";
            }
            $arrTmp[] = $value[5];
            //disposition
            $iDuracion = $value[8];
            //billsec
            $iSec = $iDuracion % 60;
            $iDuracion = (int) (($iDuracion - $iSec) / 60);
            $iMin = $iDuracion % 60;
            $iDuracion = (int) (($iDuracion - $iMin) / 60);
            $sTiempo = "{$value[8]}s";
            if ($value[8] >= 60) {
                if ($iDuracion > 0) {
                    $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                } elseif ($iMin > 0) {
                    $sTiempo .= " ({$iMin}m {$iSec}s)";
                }
            }
            $arrTmp[] = $sTiempo;
            $arrData[] = $arrTmp;
        }
    }
    $oGrid->setData($arrData);
    if ($error != "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", $error);
    }
    //begin section filter
    $smarty->assign("USERLEVEL", $credentials['userlevel']);
    $smarty->assign("SEARCH", "<input type='submit' class='button' value='" . _tr('Search') . "' name='report'>");
    if ($delete) {
        $oGrid->deleteList(_tr("Are you sure you want to delete?"), "delete", _tr("Delete Selected"), false);
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $_POST["organization"] = $domain;
        $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$domain], $_POST, array("organization" => "all"), true);
    }
    $_POST['date_start'] = $paramFiltro['date_start'];
    $_POST['date_end'] = $paramFiltro['date_end'];
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Start Date") . " = " . $paramFiltro['date_start'] . ", " . _tr("End Date") . " = " . $paramFiltro['date_end'], $paramFiltro, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true);
    //DATE START - DATE END
    $_POST["src"] = $src;
    // source
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source") . " = " . $src, $_POST, array("src" => ""));
    $_POST["dst"] = $dst;
    // destination
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination") . " = " . $dst, $_POST, array("dst" => ""));
    $_POST["src_channel"] = $src_channel;
    // source channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source Channel") . " = " . $src_channel, $_POST, array("src_channel" => ""));
    $_POST["dst_channel"] = $dst_channel;
    // destination channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination Channel") . " = " . $dst_channel, $_POST, array("dst_channel" => ""));
    $_POST["calltype"] = $calltype;
    // call type
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Call Destination") . " = " . $arrCallType[$calltype], $_POST, array("calltype" => "all"), true);
    $_POST["status"] = $status;
    // call status
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Call Status") . " = " . $arrStatus[$status], $_POST, array("status" => "all"), true);
    $_POST["accountcode"] = $accountcode;
    // destination channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Account Code") . " = " . $dst, $_POST, array("accountcode" => ""));
    $arrForm = createFieldFilter($arrOrgz, $arrCallType, $arrStatus);
    $oFilterForm = new paloForm($smarty, $arrForm);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST);
    $oGrid->showFilter(trim($htmlFilter));
    $content = $oGrid->fetchGrid();
    return $content;
}