int main(int argc, char *argv[]) { struct sockaddr_in servaddr; char buf[MAXLINE]; int sockfd, n; cgi_init(); cgi_process_form(); cgi_init_headers(); if (cgi_param("action") && cgi_param("message") && cgi_param("ip")) { sockfd = Socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; inet_pton(AF_INET, cgi_param("ip"), &servaddr.sin_addr); servaddr.sin_port = htons(SERV_PORT); Connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); strcpy(buf, cgi_param("message")); Write(sockfd, buf, strlen(buf) + 1); Close(sockfd); } cgi_end(); return 0; }
int main(void) { //Redirect before initializing headers mysqlpp::Connection c(false); if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) { cgi_redirect("./error.okz?state=err_db"); return 0; } else { //Set UTF8 mysqlpp::Query q = c.query("SET NAMES utf8"); q.exec(); } cgi_init(); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); cgi_init_headers(); header("sidebar_player_list"); menu(); sidebar(); body(c); footer(); cgi_end(); return 0; }
int main(void) { sqlite3 *db; char *err = NULL; int ret = 0; int empty = 1; char *sql = NULL; char *data; cgi_init(); cgi_process_form(); cgi_init_headers(); //printf("Content-Type:text/html\r\n\r\n"); puts("<html><head><title>login</title><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"></head><body>"); if ((cgi_param("Name") == NULL) || (cgi_param("Password") == NULL)) { puts("用户名或密码不正确,登录失败!"); exit(1); } #if 0 printf("Name=%s\t", cgi_param("Name")); printf("Password=%s\t", cgi_param("Password")); #endif ret = sqlite3_open("usr.db", &db); if (ret != SQLITE_OK) { puts(sqlite3_errmsg(db)); puts("\n"); exit(1); } sql = sqlite3_mprintf("select * from usr where name=%Q and password=%Q;", cgi_param("Name"), cgi_param("Password")); ret = sqlite3_exec(db, sql, rscallback, &empty, &err); if (ret != SQLITE_OK) { puts(err); puts("\n"); sqlite3_close(db); exit(1); } sqlite3_free(sql); if (empty != 0) { puts("用户名或密码不正确,登录失败!"); } else { puts("登录成功!"); } puts("</body></html>"); cgi_end(); sqlite3_close(db); return 0; }
int main (int argc, char **argv) { char *username; //CGI process cgi_init(); cgi_process_form(); username = cgi_param("uid"); cgi_init_headers(); /************** pagina html busca ********************/ printf("<html>\n"); printf("<head>\n"); printf(" <title>Neural TB - Lista de Pacientes</title>\n"); printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\" />\n"); printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"css/menu.css\" />\n"); printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"css/form.css\" />\n"); printf(" <script language=javascript src=\"js/funcoes.js\"></script>\n"); printf("\n"); printf(" <style>\n"); printf(" iframe {width: 100%%; min-width: 800px; height:500px}\n"); printf(" </style>\n"); printf("</head>\n"); printf("\n"); printf("<body>\n"); printf("\n"); showMenu("listar",username); printf("\n"); printf("<table border=\"0\">\n"); printf("<tr>\n"); printf(" <td class=\"under_menu\">\n"); printf(" <div align=\"center\">\n"); printf(" <table border=\"0\" style=\"width: 100%%\" cellspacing=\"0\" cellpadding=\"0\"> \n"); printf("\n"); printf(" <tr>\n"); printf(" <td><iframe src=\"listPatients.cgi?uid=%s\" frameborder=\"0\" name=\"resultado\" marginwidth=\"0\" marginheight=\"0\" style=\"width: 100%%\"></iframe></td>\n",username); printf(" </tr>\n"); printf("\n"); printf(" </table>\n"); printf(" </div>\n"); printf(" </td>\n"); printf("</tr>\n"); printf("</table>\n"); printf("</body>\n"); printf("</html>\n"); /*****************************************************/ cgi_end(); return 0; }
int main(void) { cgi_init(); cgi_session_start(); cgi_process_form(); // Is to destroy the session? if (cgi_param("confirm") && !strcmp(cgi_param("confirm"), "yes")) { cgi_session_destroy(); cgi_end(); cgi_redirect("session.cgi"); return 0; } cgi_init_headers(); puts("" "<html>" "<head><title>LibCGI session examples - Destroy session</title>" "</head>" "<body>" ""); cgi_include("session_ex1_desc.html"); puts("" "<table width='70%%' align='center'>" "<tr>" "<td>" ""); if (!cgi_session_var_exists("logged")) { puts("<font face='arial, verdana' size='2'>You are not logged yet</font>"); } else { puts("" "<font face='arial, verdana' size='2'>If you are sure to unregister the session, " "<a href='destroy.cgi?confirm=yes'>click here</a></font>" ""); } puts("</td></tr>"); cgi_include("topbar.htm"); puts("" "</table>" "</body>" "</html>" ""); cgi_end(); return 0; }
int main(void) { cgi_init(); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); cgi_init_headers(); header("sidebar_download"); menu(); sidebar(); //Beta ! std::cout << "<p class=\"wrn\">Phase de beta !<br />" "Le jeu est en phase de beta, ce qui signifie qu'il " "est fortement possible que des bugs soit présent.<br />" "Le téléchargement d'Okzoniom::Patcher permet de garder le jeu à jour " "par rapport aux dernières modifications mise en ligne." "</p>"; std::cout << "<p class=\"wrn\">" "En cas de problème, vous pouvez me faire parvenir par e-mail " "le fichier Log_Patcher.txt ou Log.txt dans le cas d'un plantage !</p>"; std::cout << "<div class=\"body\"><div class=\"main\">" "<h1>" << __tr("download") << "</h1>" "<div class=\"hr\"></div>" << std::endl; std::map<std::string, std::string> title_file; title_file["Windows"] = "Patcher_Win.exe"; title_file["Linux"] = "Patcher_Linux.tar"; for(auto it = title_file.begin(); it != title_file.end(); ++it) { std::string file = it->second; std::cout << "<h2>" << it->first << "</h2>" "<p>" "<a href=\"download/" << file << "\">" "<strong>> " << file <<" <</strong></a><br />" << infoFile(file) << "</p>" << std::endl; } std::cout << "</div></div>" << std::endl; footer(); return 0; }
void printSuccess (char *username) { cgi_init_headers(); printf ("<html>\n"); printf ("\t<head>\n"); printf ("\t\t<title>Usuário Editado</title>\n"); printf ("\t\t<meta http-equiv=\"refresh\" content=\"2; URL=busca.cgi?uid=%s\" />\n",username); printf ("\t</head>\n"); printf ("\t<body>\n"); printf ("<span style=\"background-color:green; color: white; font-family: Verdana, Arial; font-size:15pt; padding: 5px\">"); printf ("Usuário editado com sucesso. Aguarde...</span>"); printf ("\t</body>\n"); printf ("</html>"); }
int main(void) { cgi_init(); cgi_session_start(); cgi_init_headers(); puts("<html><body>"); cgi_include("session_ex1_desc.html"); puts("" "<table width='70%%' align='center'>" "<tr>" "<td align='center'>" "<font face='arial, verdana' size='4' color='orange'>Main page" ""); // The user is logged? if (cgi_session_var_exists("logged")) puts(" - logged"); else puts(" - not logged yet"); puts("" "</font>" "</td>" "</tr>" " " "<tr>" "<td><font face='arial, verdana' size='2' color='#0000ff'>" "This is the main page of LibCGI session suport test. Please choose one of the options" "in the navigation bar.</font>" "</td>" "</tr>" ""); // include the navigation bar cgi_include("topbar.htm"); puts("" "</table>" "</body>" "</html>" ""); cgi_end(); return 0; }
int main(int argc, char *argv[]) { cgi_init(); cgi_session_start(); cgi_process_form(); cgi_init_headers(); sqlite3 *db; char *err = 0; char *sql = NULL; char **result=NULL; int row=0,col=0; int ret = 0; ret = sqlite3_open(DATEBASE,&db); if(ret != SQLITE_OK) { fputs(sqlite3_errmsg(db),stderr); fputs("\n",stderr); exit(1); } sql = sqlite3_mprintf("select U_prim from UserInfo where U_id='%s' and U_pwd='%s'", cgi_param("user"),cgi_param("password")); ret = sqlite3_get_table(db,sql,&result,&row,&col,&err); if(ret != SQLITE_OK) { fputs(err,stderr); fputs("\n",stderr); sqlite3_close(db); exit(1); } if(col == 0 && row == 0) { /* 修改路径 */ printf("bad input"); printf("%s ",cgi_param("user")); cgi_include ("../htdocs/login.html"); } else { cgi_session_register_var("logged",result[1]); /* 修改系统用户跳转页面地址 */ cgi_include("../htdocs/main.html"); } sqlite3_free_table(result); sqlite3_close(db); cgi_end(); return 0; }
int main() { char *str, *delim, **e; unsigned int total, i; cgi_init(); cgi_process_form(); cgi_init_headers(); // The form was submited?? if (cgi_param("action")) { str = cgi_param("str"); delim = cgi_param("delim"); e = explode(str, delim, &total); if (total < 1) puts("explode() returned 0 items."); else { for (i = 0; i < total; i++) printf("Item offset [%d]: %s<br>", i, e[i]); } free(str); free(delim); } else { printf("" "<html><head><title>LibCGI examples - explode()</title></head>" "<body>" "%s<br><br>" "<form action='explode.cgi' method='post'>" "String: <input type='text' name='str' value='this,is,a,test'><br>" "Delimitator: <input type='text' name='delim' value=',' maxlength='1' size='2'><br>" "<input type='submit' value='explode() the string!!!' name='action'>" "</form>" "</body>" "</html>" "", example_description()); } cgi_end(); return 0; }
void libcgi_error(int error_code, const char *msg, ...) { va_list arguments; if (!cgi_display_errors) return; cgi_init_headers(); va_start(arguments, msg); printf("<b>%s</b>: ", libcgi_error_type[error_code]); vprintf(msg, arguments); puts("<br>"); va_end(arguments); if ((error_code == E_FATAL) || (error_code == E_MEMORY)) { cgi_end(); exit(EXIT_FAILURE); } }
int main(void) { cgi_init(); mysqlpp::Connection c(false); if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) { cgi_redirect("./error.okz?state=err_db"); return 0; } else { //Set UTF8 mysqlpp::Query q = c.query("SET NAMES utf8"); q.exec(); } initializeFaction(c); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); cgi_init_headers(); __tr("your_army"); header("your_army"); menu(); sidebar(); if (cgi_session_var("login") == NULL) { std::cout << "<div class=\"err\">" << __tr("profil_mustlogin") << "</div>"; } else { displayState(); show(cgi_session_var("login"), c); } footer(); return 0; }
int main (void) { sqlite3 *db; //char *err = 0; int ret = 0; char **datatable1; char **datatable3; int nRow; int nColumn; char *sql; int i; char *zErrMsg = 0; cgi_init(); cgi_init_headers(); cgi_process_form(); puts("<html><head><title>chaxun</title>"); puts("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"); //puts("<link href=\"/Style.css\" rel=\"stylesheet\" type=\"text/css\" />"); puts("</head>"); puts("<body bgColor=#fffff0>"); db = open_db("OAK.db"); sql = sqlite3_mprintf("select * from IpInfo"); ret = sqlite3_get_table(db, sql, &datatable1, &nRow, &nColumn, &zErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", zErrMsg); exit(1); } puts("<form action=\"load.cgi\">"); puts("<table width='70%' align='left' border=1 border-coer=#000066>"); puts("<tr><td width='20%'>"); puts("<select NAME = \"ip\">"); puts("<option value = \"\"> 选择IP</option> "); if (!(0 == nRow && 0 == nColumn)) { for (i = 1; i <= nRow*nColumn ; i += nColumn ) { printf("<option value = \"%s\"", datatable1[i]); if (cgi_param("company")) { if (0 == strncmp(cgi_param("ip"), datatable1[i],strlen(datatable1[i]))) printf("SELECTED"); } printf("> %s </option> ", datatable1[i]); } } puts("</select>"); puts("</td>"); puts("<td>"); puts("<input type=\"submit\" value=\"上传\" name=\"action\" >"); puts("</td></tr></table>"); sql = sqlite3_mprintf("select R.R_id,R.R_name,R.R_flag,C.C_name from ResInfo R left join CompanyInfo C on R.C_id = C.C_id;"); puts("<br />"); puts("<br />"); ret = sqlite3_get_table(db, sql, &datatable3, &nRow, &nColumn, &zErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", zErrMsg); exit(1); } puts("<table width='70%' align='left' border=1>"); puts("<tr><td style=\"width:50px\" align=center>选择</td>"); puts("<td style=\"width:150px\" align=center>媒体名称</td>"); puts("<td style=\"width:120px\" align=center>媒体类型</td>"); puts("<td style=\"width:170px\" align=center>所属公司</td>"); puts("</tr>"); if (!(0 == nRow && 0 == nColumn)) { for (i = 4; i <= nRow*nColumn ; i += nColumn ) { puts("<tr><td align='center'><input type = 'checkbox' name='xuanqu' "); printf(" value=%s />", datatable3[i+0]); puts("</td>"); printf("<td>%s</td>", datatable3[i+1]); if(atoi(datatable3[i+2]) == 0){ printf("<td>视频文件</td>"); } else { printf("<td>图片文件</td>"); } printf("<td>%s</td></tr>",datatable3[i+3]); } } puts("</table>"); puts("</form>"); puts("</body></html>"); cgi_end(); return 0; }
int main(void) { //Redirect before initializing headers mysqlpp::Connection c(false); if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) { cgi_redirect("./error.okz?state=err_db"); return 0; } else { //Set UTF8 mysqlpp::Query q = c.query("SET NAMES utf8"); q.exec(); } cgi_init(); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); std::string login = getParam("n"); cgi_init_headers(); header("sidebar_profil", ", "+login); menu(); sidebar(); std::cout << "<div class=\"body\"><div class=\"main\">"; initializeFaction(c); int id,faction, xp, level; mysqlpp::Query query = c.query("SELECT id,faction,xp,level FROM game_account where login = %0Q;"); query.parse(); mysqlpp::StoreQueryResult r = query.store(login); if (r && r.num_rows() > 0) { //Should only be one account with that name id = r[0]["id"]; //Will be used to get the number of units faction = r[0]["faction"]; xp = r[0]["xp"]; level = r[0]["level"]; std::cout << "<p>" << __tr("account") << ": <strong>" << login << "</strong><br />" << __tr("xp") << ": <strong>" << xp << "</strong><br />" << __tr("level") << ": <strong>" << level << "</strong><br />" << __tr("faction") << ": <strong>" << __tr(factionName[faction]) << "</strong>" "<div class=\"hr\"></div>" "<center><p><strong>" << __tr("army_composition") << ":</strong></p>"; //Now we have the account, get its units and their number query.reset(); query << "select unit_name,unit_number from game_unit_available where id_account = %0;"; query.parse(); mysqlpp::StoreQueryResult u = query.store(id); if (u && u.num_rows() > 0) { std::cout << "<table class=\"army\"><tr>" << "<td><strong>" << __tr("unit") << "</strong></td>" << "<td><strong>" << __tr("number") << "</strong></td></tr>"; for (size_t i = 0; i < u.num_rows(); ++i) { int num = u[i]["unit_number"]; if( num > 0) { std::string name; u[i]["unit_name"].to_string(name); std::cout << "<tr><td><strong>" << __tr(name) << "</strong></td>" << "<td><strong>" << num << "</strong></td></tr>"; } } std::cout << "</table></center>"; } else { std::cout << "<center><em>" << __tr("army_empty") << "</em></center>"; } std::cout << "</p>" << std::endl; } else { std::cout << "<p>" << __tr("player_notfound") << "</p>" << std::endl; } std::cout << "</div></div>"; footer(); return 0; }
int main (int argc, char **argv) { char *username; //CGI process cgi_init(); cgi_process_form(); username = cgi_param("uid"); cgi_init_headers(); //HTML printf("\r\n"); printf("<html>\n"); printf("<!-- Arquivo para o projeto NeuralTB -->\n"); printf("<!-- Universidade Federal do Rio de Janeiro\n"); printf(" Escola Politecnica\n"); printf(" Departamento de Engenharia Eletronica e de Computacao\n"); printf(" \n"); printf(" Laboratorio de Processamento de Sinais\n"); printf(" \n"); printf(" Autor: Luiz Evora\n"); printf(" Atualizacao: Laura de Oliveira Fernandes Moraes\n"); printf(" Ultima atualizacao: 29/07/2008 -->\n"); printf("\n"); printf(" <head>\n"); printf("\n"); printf(" <meta http-equiv=content-type content=\"text/html; charset=UTF-8\">\n"); printf("\n"); printf(" <title>.:. Neural TB .:. Busca de pacientes</title>\n"); printf("\n"); printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"../css/standart.css\"/>\n"); printf("\n"); printf(" <script language=\"javascript\" src=\"../js/xml.js\"></script>\n"); printf(" <script language=\"javascript\" src=\"../js/busca.js\"></script>\n"); printf("\n"); printf("<script>\n"); printf("\n"); printf(" var linha=0;\n"); printf("\n"); printf(" function contaLinhas()\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" linha+=1;\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" </script>\n"); printf("\n"); printf("\n"); printf("\n"); printf(" </head>\n"); printf("\n"); printf("\n"); printf("\n"); printf("<!-- <body onLoad=\"displayResult('xml','../xml/pacientes.xml','../xml/nomes.xsl');\" class=\"style1\">-->\n"); printf("\n"); printf("<body class=\"style1\">\n"); printf("\n"); printf(" <table height=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id= \"d\">\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td><b><u><font size=\"5\">Menu</font></u></b></td>\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td width=\"100%%\">\n"); printf("\n"); printf(" <a href=\"formulario.cgi?uid=%s\">Adicionar Paciente</a> \n", username); printf("\n"); printf(" <a href=\"busca.cgi?uid=%s\"> Buscar/Editar/Remover</a> \n", username); printf("\n"); printf(" <a href=\"backup.cgi\"> Back-up</a> \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" <a href=\"principal.cgi?uid=%s\">Página principal</a>\n", username); printf("\n"); printf(" </td>\n"); printf("\n"); printf(" <td></td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td>\n"); printf("\n"); printf(" <a href=\"exibirPacientes.cgi?uid=%s\">Exibir questionários</a> \n", username); printf("\n"); printf(" <a href=\"exibirRecusa.cgi?uid=%s\">Exibir recusas</a>\n", username); printf("\n"); printf(" </td>\n"); printf("\n"); printf(" <td></td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" </table>\n"); printf("\n"); printf(" <a id=\"xml1\" href=\"\"></a>\n"); printf(" \n"); printf(" <form action=\"searchPatient.cgi?uid=%s\" method=\"post\" name=\"check\" id=\"searchForm\" onSubmit=\"return validarBusca(this);\" />\n", username); printf("<input type=\"HIDDEN\" name=\"uid\" value=\"%s\">\n",username); printf(" <table width=\"70%%%%\" border=\"0\" cellpadding=\"1\" cellspacing=\"2\" bordercolor=\"#999999\" id=\"tabela\" align=center>\n"); printf(" <tr class=\"styleBusca1\">\n"); printf(" <td width=\"30%%%%\" title=\"Atributo através do qual será realizada a busca\">\n"); printf(" <div class=\"styleBusca2\"> Busca por</div>\n"); printf(" </td>\n"); printf(" <td width=\"20%%%%\" id=\"operador_0\"> </td>\n"); printf(" <td id=\"VALORES_TITULO\" width=\"40%%%%\">\n"); printf(" <div class=\"styleBusca2\"> </div>\n"); printf(" </td>\n"); /*printf(" <td id=\"ORDENA_TITULO\" width=\"10%%%%\" title=\"Ordena os pacientes buscados de acordo com o atributo selecionado\">\n"); printf(" <div class=\"styleBusca2\"> Ordenar por</div>\n"); printf(" </td>\n");*/ printf(" </tr>\n"); printf(" <tr class=\"fundoTabela\">\n"); printf(" <td title=\"Atributo através do qual será realizada a busca\">\n"); printf(" <div align=\"center\"><strong><font color=\"#003399\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">\n"); printf(" <!-- select da celula [1][0] -->\n"); printf(" <select name=\"select\" onChange=\"_options(this);\" onKeyUp=\"_options(this.form);\">\n"); printf(" <option value=\"1\" selected> Selecione</option>\n"); printf(" <option value=\"2.nome\">Nome</option>\n"); //Opcao 2 para nomes printf(" <option value=\"3.diaNasc\">Data de nascimento</option>\n"); //Opcao 3 para datas printf(" <option value=\"4.cidade\">Cidade de estudo</option>\n"); //Opcao 4 para escolhas restritas (com opcoes) printf(" <option value=\"3.diaEntr\">Data da entrevista</option>\n"); //Opcao 3 para datas printf(" </select>\n"); printf(" </font></strong></div>\n"); printf(" </td>\n"); printf(" <td id=\"operadores\"> </td>\n"); printf(" <td id=\"valores\"> </td>\n"); /*printf(" <td id=\"ordena\" title=\"Ordena os pacientes buscados de acordo com o atributo selecionado\">\n"); printf(" <!-- select da celula [1][3] -->\n"); printf(" <select name=\"selectOrdena\">\n"); printf(" <option value=\"id\" selected>Nº de identificação</option>\n"); printf(" <option value=\"nome\">Nome</option>\n"); printf(" <option value=\"diaNasc\">Data de Nascimento</option>\n"); printf(" <option value=\"cidade\">Cidade de estudo</option>\n"); printf(" </select>\n"); printf(" </td> \n");*/ printf(" </tr>\n"); printf(" </table>\n"); printf("<p align=center> <input type=\"submit\" name=\"Submit\" value=\"Pesquisar\"> </p>\n"); printf("</form>\n"); printf("\n"); printf("<div align=center><h3> Pacientes Inseridos</h3></div>\n"); printf("\n"); printf("<div id=\"xml\">\n"); printf("\n"); printf("</div>\n"); printf("\n"); printf("<table width=\"600\" align=\"center\" cellspacing=\"1\" cellpadding=\"0\" id=\"xml1\">\n"); printf("<tr class=\"nome\" align=\"center\">\n"); printf("<td><h4>Número</h4></td>"); printf("<td><h4>Nome</h4></td>"); printf("<td><h4>Data de nascimento</h4></td>"); printf("<td><h4>Data da entrevista</h4></td>"); printf("<td><h4>Remover</h4></td>"); printf("<td><h4> Editar </h4></td></tr>"); printf("\n"); printf(" <script>\n"); printf("\n"); printf("\n"); printf("\n"); printf(" var xmlDoc=null;\n"); printf("\n"); printf(" if (window.ActiveXObject)\n"); printf("\n"); printf(" {// code for IE\n"); printf("\n"); printf(" xmlDoc=new ActiveXObject(\"Microsoft.XMLDOM\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" else if (document.implementation.createDocument)\n"); printf("\n"); printf(" {// code for Mozilla, Firefox, Opera, etc.\n"); printf("\n"); printf(" xmlDoc=document.implementation.createDocument(\"\",\"\",null);\n"); /*printf(" document.write(\"<td></td>\");"); printf(" document.write(\"<td><h4>Número</h4></td>\");"); printf(" document.write(\"<td><h4>Nome</h4></td>\");"); printf(" document.write(\"<td><h4>Data de nascimento</h4></td>\");"); printf(" document.write(\"<td><h4>Remover</h4></td>\");"); printf(" document.write(\"<td><h4> Editar </h4></td>\");");*/ printf("\n"); printf(" }\n"); printf("\n"); printf(" else\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" alert('Your browser cannot handle this script');\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" if (xmlDoc!=null)\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" xmlDoc.async=false;\n"); printf("\n"); printf(" xmlDoc.load(\"../xml/pacientes.xml\");\n"); printf(" var fname = 0;\n"); printf("\n"); printf("\n"); printf("\n"); printf(" var x=xmlDoc.getElementsByTagName(\"paciente\");\n"); //printf("document.write('</tr>');"); printf("\n"); printf(" for (i=0;i<x.length;i++)\n"); printf("\n"); printf(" { \n"); printf("\n"); printf(" contaLinhas();\n"); printf("\n"); printf("if (!(i %% 2))\n"); printf(" document.write(\"<tr class='par'>\");\n"); printf(" else\n"); printf(" document.write(\"<tr class='impar'>\");\n"); printf("\n"); //printf(" document.write(\"<td></td>\");\n"); printf("\n"); printf(" document.write(\"<td width='50' align='center'>\" + linha + \".</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"nome\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf(" document.write(\"<td class='link' align='center' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"diaNasc\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"mesNasc\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"anoNasc\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' align='center' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"diaEntr\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"mesEntr\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"anoEntr\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' align='center'>\");\n"); //printf(" var endereco = \"remover.cgi?paciente=\" + (i+1) + \"&uid=%s>\"\n",username); printf(" var endereco = \"remover.cgi?paciente=\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \"&uid=%s>\"\n",username); printf(" document.write(\"<a href=\" + endereco + \"Remover\" + \"</a>\");\n"); printf(" document.write(\"</td>\");\n"); printf(" document.write(\"<td class='link' align='center'>\");\n"); //printf(" endereco = \"editar.cgi?paciente=\" + (i+1) + \"&uid=%s>\"\n",username); printf(" endereco = \"editar.cgi?paciente=\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \"&uid=%s>\"\n",username); printf(" document.write(\"<a href=\" + endereco + \"Editar\" + \"</a>\");\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf("\n"); printf(" document.write(\"</tr>\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" //document.write(\"</table>\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf("\n"); printf("\n"); printf(" </script>\n"); printf("\n"); printf("</table>\n"); printf("\n"); printf(" </body>\n"); printf("\n"); printf("</html>\n"); printf("\n"); printf("\n"); cgi_end(); return 0; }
void printError (char *msg) { cgi_init_headers(); printf ("<html><head><title>Erro</title></head><body><h2>%s</h2></body></html>", msg); }
int main (void) { //modificaçoes xsltproc char tempname [L_tmpnam]; char comando[100]; char address[100]; //2 de 6 FILE *xsl; //size_t len; //char xmlSearchResultFilePath[FILE_NAME_MAX]; //char healthCenter[HEALTH_CENTER_NAME_MAX]; formvars *first; char *pid; cgi_init(); //modificações xsltproc cgi_init_headers(); fflush(stdout); //3de 6 /****************************************************************************** * READ CONTENT STRING FROM SERVER. * * PROCESS DATA. * * CREATE A LINKED LIST. * ******************************************************************************/ first = cgi_process_form(); /****************************************************************************** * ACQUIRE VALUES CHOSEN BY USER * ******************************************************************************/ pid = cgi_param("pid"); /****************************************************************************** * CREATE XSL SEARCH FILE * ******************************************************************************/ //modificações xsltproc if (tmpnam(tempname) != NULL) { xsl = fopen(tempname, "w"); // 4 de 6 fprintf(xsl,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\r\n"); // fprintf(xsl," xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"\r\n"); // fprintf(xsl," xmlns=\"http://www.w3.org/1999/xhtml\">\r\n"); fprintf(xsl,"<xsl:output omit-xml-declaration=\"yes\" encoding=\"ISO-8859-1\" method=\"xml\"/>\r\n"); fprintf(xsl,"\r\n"); getUserPublicPath(address); fprintf(xsl,"<xsl:include href=\"%s/xml/xsl/fullPatientDetails2.xsl\" />\r\n",address); // 5... fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:template match=\"/\">\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <xsl:apply-templates select=\"pacientes\" />\r\n"); fprintf(xsl," \r\n"); fprintf(xsl,"</xsl:template>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:template match=\"pacientes\">\r\n"); fprintf(xsl," <!-- Tags' values -->\r\n"); fprintf(xsl," <xsl:for-each select=\"paciente[@removido = 'nao']\">\r\n"); fprintf(xsl," <xsl:sort select=\"descendant::nomeCompleto\" />\r\n"); fprintf(xsl," <xsl:if test=\"triagem/numeroGeral = '%s'\">\r\n", pid); fprintf(xsl," <table>\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Critério Inicial de Triagem para TB</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"triagem\" />\r\n"); /* fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Questionário de Custos - Parte A</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"custosA\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Consulta Médica</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"consultaMedica\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td class=\"title3\" colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th class=\"title3\" colspan=\"2\">Questionário de Custos - Partes B e C</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"custosBeC\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td class=\"title3\" colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Follow Up - 90 dias</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"followUp\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th class=\"title3\">Gráfico de Grupo</th>\r\n"); fprintf(xsl," <td><!--<a href=\"{concat(graficoGrupo, triagem/numeroGeral)}\" target=\"_blank\">Visualizar</a>--></td>\r\n"); fprintf(xsl," </tr>\r\n"); */ fprintf(xsl," </table>\r\n"); fprintf(xsl," <br /><br />\r\n"); fprintf(xsl," </xsl:if>\r\n"); fprintf(xsl," </xsl:for-each>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl,"</xsl:template>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"</xsl:stylesheet>\r\n"); fclose(xsl); //Modificações xsltproc } else printError("Erro ao criar arquivo temporário!\n"); // 5 de 6 /****************************************************************************** * PRINTING RESULT * ******************************************************************************/ //Modificações xsltproc printf("<html>\n"); printf("<head>\n"); printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/imprimir.css\" />\n"); printf("\t<title>Versão de Impressão</title>\n"); printf("</head>\n"); printf("<body id=\"result\" onLoad=\"window.print()\">\n"); sprintf(comando,"xsltproc %s xml/pacientesGuadalupe.xml 2>&1",tempname); fflush(stdout); system(comando); sprintf(comando,"rm %s 2>&1",tempname); system(comando); printf("</body>\n"); printf("</html>"); // 6 de 6 /****************************************************************************** * FREE MEMORY AND EXIT * ******************************************************************************/ cgi_end(); return (ok); }
int main (void) { char *formName, *pid, *username, *newPid; boolean found_patient; FILE *document; /* libcgi declarations */ formvars *first_input, *input; /* libxml2 declarations */ xmlChar *strUTF = NULL; xmlDocPtr doc; xmlNodePtr root_element, cur_node, new_form, new_node, edited_patient, old_patient; /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /****************************************************************************** * READ CONTENT STRING FROM SERVER. * * PROCESS DATA. * * CREATE A LINKED LIST. * ******************************************************************************/ cgi_init(); first_input = cgi_process_form(); newPid = cgi_param("numeroGeral"); pid = cgi_param("antigoNumeroGeral"); formName = cgi_param("form"); //username = cgi_param("uid"); if(!(username= getenv("REMOTE_USER"))) //verifica se string lida é null { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<head>\n"); printf("<title>Resultado</title>\n"); printf("</head>\n"); printf("<body>\n"); printf("Erro ao verificar o usuário."); printf("</body>\n"); printf("</html>\n"); exit(0); } if ((!pid) || (!formName)) { printError("ID do paciente e nome do formulário não foram enviados"); usualFreeMemory(NULL); exit(0); } /****************************************************************************** * OPENING AND PARSING AN XML FILE TO A TREE * ******************************************************************************/ document = fopen(XML_FILE_PATH, "r+"); if (document == NULL) { printError("O arquivo de pacientes não pode ser aberto"); exit(0); } if(flock(fileno(document), LOCK_EX)) { printError("Erro ao trancar o arquivo"); fclose(document); exit(0); } //printWait("Trancado!"); //sleep(20); doc = xmlReadFd(fileno(document), XML_FILE_PATH, NULL, XML_PARSE_NOBLANKS); if (doc == NULL) { printError("Failed to parse doc"); usualFreeMemory(NULL); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } root_element = xmlDocGetRootElement(doc); /****************************************************************************** * SEARCH THE SAME <numeroGeral> * ******************************************************************************/ cur_node = root_element->children; /* Get the node <paciente> if file isn't empty */ if (!cur_node) //test!!!! printf!! pode-se tb na remocao exigir a remocao do arquivo se o paciente excluido for o unico do arquivo found_patient = false; else { /* looping through patients looking for the right patient */ for (found_patient = false; ((!found_patient) && (cur_node)); cur_node = cur_node->next) { cur_node = cur_node->children; /* <triagem> */ cur_node = cur_node->children; /* <numeroGeral> ? */ while ((!xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) && (cur_node)) cur_node = cur_node->next; if (xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) { if (xmlStrEqual(cur_node->children->content, BAD_CAST pid)) { found_patient = true; old_patient = cur_node->parent; /*old_paciente recebe o noh <triagem> do paciente que possui o numeroGeral procurado */ } else { cur_node = cur_node->parent; /* <triagem> */ cur_node = cur_node->parent; /* <paciente> */ } } else { printError("Erro de formação do XML. Tem paciente sem número geral."); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } } } /****************************************************************************** * CHECK IF PATIENT WAS FOUND * * IF TRUE, EXIT * ******************************************************************************/ if (!found_patient) { printError("Este paciente não existe."); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } /****************************************************************************** * Verificando se o novo numero geral jah existe * *******************************************************************************/ cur_node = root_element->children; /* Get the node <paciente> if file isn't empty */ if (!cur_node) //test!!!! printf!! pode-se tb na remocao exigir a remocao do arquivo se o paciente excluido for o unico do arquivo found_patient = false; else { /* looping through patients looking for the right patient */ for (found_patient = false; ((!found_patient) && (cur_node)); cur_node = cur_node->next) { cur_node = cur_node->children; /* <triagem> */ cur_node = cur_node->children; /* <numeroGeral> ? */ while ((!xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) && (cur_node)) cur_node = cur_node->next; if (xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) { if (xmlStrEqual(cur_node->children->content, BAD_CAST newPid)) { found_patient = true; old_patient = cur_node->parent; /*old_paciente recebe o noh <triagem> do paciente que possui o numeroGeral procurado */ } else { cur_node = cur_node->parent; /* <triagem> */ cur_node = cur_node->parent; /* <paciente> */ } } else { printError("Erro de formação do XML. Tem paciente sem número geral."); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } } } /****************************************************************************** * Comfirmando se novo numero geral jah existe * *******************************************************************************/ if((found_patient) && (strcmp(newPid,pid) != 0)) { printError("O novo número geral escolhido já existe."); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } /****************************************************************************** * CRIANDO NOVO FORMULARIO DE TRIAGEM * ******************************************************************************/ edited_patient = xmlNewNode (NULL,BAD_CAST "triagem"); /****************************************************************************** * ADD NEW FORM * ******************************************************************************/ strUTF = fixCgiStr(BAD_CAST formName); if (!strUTF) { cgi_init_headers(); printError("Erro na conversão de formName para UTF-8"); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } new_form = xmlNewChild (edited_patient, NULL, BAD_CAST strUTF, NULL); free(strUTF);//frees formName for (input = first_input; input; input = input->next) { if (!strcmp(input->name,"form")) input = input->next; if (!strcmp(input->name,"uid")) input = input->next; if (!strcmp(input->name,"antigoNumeroGeral")) input = input->next; /* Validate tag name input against UTF-8 */ strUTF = fixCgiStr((unsigned char *)input->name); if (!strUTF) { printError("Erro na conversão de input->name para UTF-8"); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } new_node = xmlNewNode (NULL, strUTF); free(strUTF);//frees input->name /* Validate tag value input against UTF-8 */ strUTF = fixCgiStr((unsigned char *)input->value); if (!strUTF) { printError("Erro na conversão de input->value para UTF-8"); usualFreeMemory(doc); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } xmlNodeAddContent (new_node, strUTF); free(strUTF);//frees input->value xmlAddChild (new_form, new_node); } /****************************************************************************** * Substituindo o noh antigo pelo novo * ******************************************************************************/ xmlReplaceNode (old_patient, edited_patient->children); xmlFreeNode (old_patient); /****************************************************************************** * DUMPING DOCUMENT TO FILE * ******************************************************************************/ if ((xmlSaveFormatFileEnc(XML_FILE_PATH, doc, "ISO-8859-1", 1)) < 0) { printError("Erro ao salvar arquivo"); usualFreeMemory(doc); xmlFreeNode(edited_patient); flock(fileno(document), LOCK_EX); fclose(document); exit(0); } /*remove(XML_FILE_PATH); if (rename(XML_TEMP_FILE, XML_FILE_PATH)) { printError("Erro ao renomear o arquivo atualizado"); usualFreeMemory(doc); exit(0); }*/ /****************************************************************************** * FREE MEMORY AND EXIT * ******************************************************************************/ printSuccess(username); usualFreeMemory(doc); xmlFreeNode(edited_patient); flock(fileno(document), LOCK_EX); fclose(document); autoBackup(); return 0; }