1 && !isset($_POST['execute'])) { $campanha = campanhasPausa($id); foreach ($column as $key => $value) { if ($value == "king_camp_horaini") { $column[$value] = explode(" ", $campanha['datetime_ini'])[1]; } else if ($value == "king_camp_horafim") { $column[$value] = explode(" ", $campanha['datetime_fin'])[1]; } else { $column[$value] = $campanha[str_replace('king_camp_', "", $value)]; } unset($column[$key]); } } else { /** * CONFIGURACOES DEFAULT */ foreach ($column as $key => $value) { $column[$value] = ${str_replace('king_camp_', "", $value)}; unset($column[$key]); } $resp = GetConfiguracao($dbcon); } /** * ALTERA AS CONFIGURACOES DE UMA CAMPANHA DO KING */ if($id > 1 && isset($_POST['execute'])){ alteraCampanhaKing($id, $column); $message = GetMessage("A configuração foi executada com sucesso!", 'S'); unset($resp); } /** * ALTERA AS CONFIGURACOES GERAL DO KING */ if (isset($_POST['execute']) && $id <= 1) { SetConfiguracao($dbcon, $column); if (pg_last_error()) { throw new Exception('Não foi possível salvar as configurações!'); } $message = GetMessage("A configuração foi executada com sucesso!", 'S'); $resp = GetConfiguracao($dbcon); } } catch (Exception $ex) { $message = GetMessage($ex->getMessage(), 'E'); } $smarty->assign("message", $message); $smarty->assign("id", $resp['id_camp_king'] ? $resp['id_camp_king'] : $id); foreach ($column as $key => $value) { $smarty->assign(str_replace("king_camp_", "", $key), $resp[$key] ? $resp[$key] : $value); } /* * Carrega o template correspondente ao cadastro */ GetTemplate($smarty, $template); function GetConfiguracao($dbcon) { $query = "SELECT * FROM pbx_kingdialer_campanha WHERE id_camp_king = 1"; $result = pg_query($dbcon, $query); return pg_fetch_assoc($result); } function SetConfiguracao($dbcon, $column) { $resp = GetConfiguracao($dbcon); if (!$resp['id_camp_king']) { foreach ($column as $key => $values) { $column[$key] = QuotedStr($values); } $query = "INSERT INTO pbx_kingdialer_campanha (" . implode(',', array_keys($column)) . ") VALUES (" . implode(',', array_values($column)) . ");"; } else { $query = "UPDATE pbx_kingdialer_campanha SET "; $x = 0; foreach ($column as $key => $value) { $x++; $query .= "$key = '{$value}'"; if ($x != count($column)) { $query .= ", "; } } $query .= " WHERE id_camp_king = {$resp['id_camp_king']}"; } pg_query($dbcon, $query); } function GetMessage($message, $type) { if (strtoupper($type) == 'E' || strtoupper($type) == 'ERRO') { return "

ERRO: $message

"; } if (strtoupper($type) == 'S' || strtoupper($type) == 'SUCESSO') { return "

SUCESSO: $message

"; } } ?>