/** * Procedimiento para guardar un arreglo de trunks para billing * * @param array $listaTrunks lista trunks para billing * * @return bool VERDADERO si se guardaron correctamente, FALSO en error */ function saveTrunksBill($listaTrunks) { $bExito = FALSE; if (!is_array($listaTrunks)) { $this->errMsg = "Values for trunks are invalid"; } else { foreach ($listaTrunks as $trunk) { $sPeticionSQL = paloDB::construirInsert("trunk_bill", array("trunk" => paloDB::DBCAMPO($trunk))); if ($this->_DB->genQuery($sPeticionSQL)) { $bExito = TRUE; } else { $this->errMsg = $this->_DB->errMsg; } } } return $bExito; }
function procesarValorCampos($caller_id, $pDB, &$numActualizados, &$numInsertados) { $SQLConsultaCallerId = 'select * from dont_call where caller_id=' . paloDB::DBCAMPO($caller_id); $resConsultaCallerId = $pDB->fetchTable($SQLConsultaCallerId, true); if (!count($resConsultaCallerId) > 0) { $sPeticionSQL = paloDB::construirInsert("dont_call", array("caller_id" => paloDB::DBCAMPO($caller_id), "date_income" => paloDB::DBCAMPO(date('Y-m-d H-i-s')), "status" => paloDB::DBCAMPO('I'))); $result = $pDB->genQuery($sPeticionSQL); if (!$result) { $this->guardarMensaje("Error al ingresar el registro"); } else { $numInsertados++; } } }
/** * Procedimiento para crear un nuevo rate * * @param string $prefix prefix para el rate * @param string $name nombre para el rate * @param string $rate rate * @param string $rate_offset rate_offset * @param string $trunk trunk for this rate * * @return bool VERDADERO si el rate se crea correctamente, FALSO en error */ function createRate($prefix, $name, $rate, $rate_offset, $trunk) { $bExito = FALSE; if ($prefix == "" && $num_digits == "") { $this->errMsg = "Prefix can't be empty"; } else { //verificar que no exista la misma combinacion de prefijo $sPeticionSQL = "SELECT id FROM rate " . " WHERE prefix = '{$prefix}' AND trunk = '{$trunk}'"; $arr_result =& $this->_DB->fetchTable($sPeticionSQL); if (is_array($arr_result) && count($arr_result) > 0) { $bExito = FALSE; $this->errMsg = "Rate for prefix already exists"; } else { $sPeticionSQL = paloDB::construirInsert("rate", array("prefix" => paloDB::DBCAMPO($prefix), "name" => paloDB::DBCAMPO($name), "rate" => paloDB::DBCAMPO($rate), "rate_offset" => paloDB::DBCAMPO($rate_offset), "trunk" => paloDB::DBCAMPO($trunk))); if ($this->_DB->genQuery($sPeticionSQL)) { $bExito = TRUE; } else { $this->errMsg = $this->_DB->errMsg; } } } return $bExito; }
/** * Procedimiento para crear un nuevo menu * * @param string $id * @param string $name * @param string $id_parent * @param string $type * @param string $link * @param string $order * * @return bool VERDADERO si el menu se crea correctamente, FALSO en error */ function createMenu($id, $name, $id_parent, $type = 'module', $link = '', $order = -1) { $bExito = FALSE; if ($id == "" && $name == "") { $this->errMsg = "ID and module name can't be empty"; } else { //verificar que no exista el mismo menu $sPeticionSQL = "SELECT id FROM menu " . " WHERE id = '{$id}' AND Name='{$name}' AND IdParent='{$id_parent}'"; $arr_result =& $this->_DB->fetchTable($sPeticionSQL); if (is_array($arr_result) && count($arr_result) > 0) { $bExito = FALSE; $this->errMsg = "Menu already exists"; } else { if ($order != -1) { $sPeticionSQL = paloDB::construirInsert("menu", array("id" => paloDB::DBCAMPO($id), "Name" => paloDB::DBCAMPO($name), "Type" => paloDB::DBCAMPO($type), "Link" => paloDB::DBCAMPO($link), "IdParent" => paloDB::DBCAMPO($id_parent), "order_no" => paloDB::DBCAMPO($order))); } else { $sPeticionSQL = paloDB::construirInsert("menu", array("id" => paloDB::DBCAMPO($id), "Name" => paloDB::DBCAMPO($name), "Type" => paloDB::DBCAMPO($type), "Link" => paloDB::DBCAMPO($link), "IdParent" => paloDB::DBCAMPO($id_parent))); } if ($this->_DB->genQuery($sPeticionSQL)) { $bExito = TRUE; } else { $this->errMsg = $this->_DB->errMsg; } } } return $bExito; }
/** * Procedimiento que agrega números a una campaña existente. La lista de * números consiste en un arreglo de tuplas, cuyo elemento __PHONE_NUMBER * es el número de teléfono, y el resto de claves es el conjunto clave->valor * a guardar en la tabla call_attribute para cada llamada * * @param int $idCampaign ID de Campaña * @param array $listaNumeros Lista de números como se describe arriba * array('__PHONE_NUMBER' => '1234567', 'Name' => 'Fulano de Tal', 'Address' => 'La Conchinchina') * * @return bool VERDADERO si todos los números fueron insertados, FALSO en error */ function addCampaignNumbers($idCampaign, $listaNumeros) { $bExito = FALSE; if (!ereg('^[[:digit:]]+$', $idCampaign)) { $this->errMsg = 'ID de campaña no es numérico'; } elseif (!is_array($listaNumeros)) { $this->errMsg = 'Lista de números tiene que ser un arreglo'; } else { $bContinuar = TRUE; $listaValidada = array(); // Se usa copia porque tupla se modifica en validación // Verificar si todos los elementos son de max. 4 parametros y son // todos numéricos o NULL if ($bContinuar) { foreach ($listaNumeros as $tuplaNumero) { /* if (count($tuplaNumero) < 1) { $this->errMsg = "Encontrado elemento sin número telefónico"; $bContinuar = FALSE; } elseif (!ereg('^[[:digit:]]+$', $tuplaNumero[0])) { $this->errMsg = "Teléfono encontrado que no es numerico"; $bContinuar = FALSE; } elseif (count($tuplaNumero) > 1 + 4) { $this->errMsg = "Para teléfono $tuplaNumero[0]: implementación actual soporta máximo 4 parámetros"; break; } else { $iCount = count($tuplaNumero) - 1; for ($i = 1; $i <= $iCount; $i++) { if (trim($tuplaNumero[$i]) == '') $tuplaNumero[$i] = NULL; if (!is_null($tuplaNumero[$i]) && !is_numeric($tuplaNumero[$i])) { $this->errMsg = "Para teléfono $tuplaNumero[0] se encontró parámetro $i = $tuplaNumero[$i] no numérico"; $bContinuar = FALSE; } } if ($bContinuar) $listaValidada[] = $tuplaNumero; } */ if (!isset($tuplaNumero['__PHONE_NUMBER'])) { $this->errMsg = "Encontrado elemento sin número telefónico"; $bContinuar = FALSE; } elseif (!ereg('^[[:digit:]#*]+$', $tuplaNumero['__PHONE_NUMBER'])) { $this->errMsg = "Teléfono encontrado que no es numerico"; $bContinuar = FALSE; } else { if ($bContinuar) { $listaValidada[] = $tuplaNumero; } } if (!$bContinuar) { break; } } } if ($bContinuar) { // Inicia transacción if (!$this->_DB->genQuery("BEGIN TRANSACTION")) { $this->errMsg = $this->_DB->errMsg; } else { foreach ($listaValidada as $tuplaNumero) { $campos = array('id_campaign' => $idCampaign, 'phone' => paloDB::DBCAMPO($tuplaNumero['__PHONE_NUMBER']), 'status' => NULL); $sPeticionSQL = paloDB::construirInsert("calls", $campos); $result = $this->_DB->genQuery($sPeticionSQL); if (!$result) { $bContinuar = FALSE; $this->errMsg = $this->_DB->errMsg . "<br/>{$sPeticionSQL}"; break; } $id_call = NULL; // TODO: investigar equivalente de LAST_INSERT_ID() en SQLite $sPeticionSQL = "SELECT MAX(id) FROM calls WHERE id_campaign = {$idCampaign} and phone = '{$tuplaNumero['__PHONE_NUMBER']}' and status IS NULL"; $tupla =& $this->_DB->getFirstRowQuery($sPeticionSQL); if (!is_array($tupla)) { $this->errMsg = $this->_DB->errMsg . "<br/>{$sPeticionSQL}"; $bContinuar = FALSE; } else { $id_call = (int) $tupla[0]; } if ($bContinuar) { foreach ($tuplaNumero as $sClave => $sValor) { if ($sClave !== '__PHONE_NUMBER') { $campos = array('id_call' => $id_call, 'key' => paloDB::DBCAMPO($sClave), 'value' => paloDB::DBCAMPO($sValor)); $sPeticionSQL = paloDB::construirInsert("call_attribute", $campos); $result = $this->_DB->genQuery($sPeticionSQL); if (!$result) { $bContinuar = FALSE; $this->errMsg = $this->_DB->errMsg . "<br/>{$sPeticionSQL}"; break; } } } } if (!$bContinuar) { break; } } $bExito = $bContinuar; if ($bExito) { $this->_DB->genQuery("COMMIT"); } else { $this->_DB->genQuery("ROLLBACK"); } } } } return $bExito; }
/** * Procedimiento para crear un nuevo grupo * * @param string $group Login del usuario a crear * @param string $description Descripción del usuario a crear * * @return bool VERDADERO si el grupo se crea correctamente, FALSO en error */ function createGroup($group, $description) { $bExito = FALSE; if ($group == "") { $this->errMsg = "Group can't be empty"; } else { if (!$description) { $description = $group; } // Verificar que el nombre de Grupo no existe previamente $id_group = $this->getIdGroup($group); if ($id_group !== FALSE) { $this->errMsg = "Group already exists"; } elseif ($this->errMsg == "") { $sPeticionSQL = paloDB::construirInsert("acl_group", array("name" => paloDB::DBCAMPO($group), "description" => paloDB::DBCAMPO($description))); if ($this->_DB->genQuery($sPeticionSQL)) { $bExito = TRUE; } else { $this->errMsg = $this->_DB->errMsg; } } } return $bExito; }