#include #include #include #include #include #include "../fdpass.h" #include using namespace std; //#include "../proto/trlid_client.protoch" #include "../proto/trlid_admin.protoch" #include "../proto/trli-sessiond_admin.protoch" static string w_session; static struct USERINFO{ string name; string email; bool is_admin; int lang; USERINFO(){ lang = 0; is_admin = false; } } userinfo; static W_SSTRING w_email("email"); static W_SSTRING w_password("password"); static W_SSTRING w_newsid("newsid"); static W_SSTRING w_title("title"); static W_SSTRING w_url("url"); static W_SSTRING w_content("content"); static W_SSTRING new_nickname("nickname"); static W_SSTRING new_email ("new_email"); static W_SSTRING new_password1 ("new_password1"); static W_SSTRING new_password2 ("new_password2"); static W_UNSIGNED w_sub1("sub1"); static W_UNSIGNED w_sub2("sub2"); static W_UNSIGNED w_sub3("sub3"); static W_UNSIGNED w_sub4("sub4"); static W_UNSIGNED w_sub5("sub5"); static W_UNSIGNED w_sub6("sub6"); static W_UNSIGNED w_sub7("sub7"); static const int step_approvenews=2; static const int step_approveone=3; static const int step_class=4; static void print_aref (const char *title, int step, W_SSTRING &var) { printf ("%s\n",tlmpweb_curpage(),step,var.getname(),var.c_str(),title); } static void print_aref (const char *title, int step, W_SSTRING &var1, W_SSTRING &var2) { printf ("%s\n",tlmpweb_curpage(),step ,var1.getname(),var1.c_str() ,var2.getname(),var2.c_str() ,title); } static void print_aref (const char *title, int step, W_SSTRING &var1, W_SSTRING &var2, W_SSTRING &var3) { printf ("%s\n",tlmpweb_curpage(),step ,var1.getname(),var1.c_str() ,var2.getname(),var2.c_str() ,var3.getname(),var3.c_str() ,title); } static void show_buttons(_F_websteps *c) { int step = c->getcurstep(); /- /-
printf ("Main page\n",tlmpweb_curdir()); if (step != 1){ /- c->url_gotostep (1," Admin menu"); } if (step == step_approveone){ c->url_gotostep (step_approvenews," Approvenews"); } /- printf ("session: %s",w_session.c_str()); if (userinfo.name.size()>0) printf (" Welcome %s\n
",userinfo.name.c_str()); /-

} extern "C" void webmain() { glocal CONNECT_INFO con; glocal CONNECT_INFO con_sess; glocal.con.port = "/dev/trlid.sock"; glocal.con.secret = "adm"; glocal.con_sess.port = "/dev/sessiond.sock"; glocal.con_sess.secret = "adm"; const char *ptsession = tlmpweb_getcookie("session"); if (ptsession == NULL){ /- No session }else{ w_session=ptsession; (glocal.con_sess,w_session.c_str()); if (success){ userinfo.lang = lang; userinfo.name = name; userinfo.email = email; userinfo.is_admin = admin; }else{ /- Invalid session } } if (w_session.empty()) return; if (!userinfo.is_admin){ /- No right to be there return; } /-

(); if (step > 3){ step = 1; } show_buttons(this); /- Menu /-

    /-
  • url_gotostep(step_approvenews,"Approve news"); /-
  • url_gotostep(step_class,"Classification"); /-
show_buttons(this); /- News to approve /-
    (glocal.con,w_session.c_str(),0,10); for (unsigned i=0; i w_newsid=newsids[i]; glocal.websteps.url_gotostep (step_approveone,w_newsid,newsids[i]); } /-
show_buttons(this); (glocal.con,w_session.c_str(),w_newsid.c_str()); if (success){ glocal const char *nickname = nickname; glocal const char *title = title; glocal const char *url = url; glocal const char *content = content; glocal const char *submit = submit; ("acceptnews"); bool valsub[7]; if (first){ w_title = glocal.title; w_url = glocal.url; w_content = glocal.content; for (auto &b:valsub) b=false; }else{ valsub[0] = w_sub1; valsub[1] = w_sub2; valsub[2] = w_sub3; valsub[3] = w_sub4; valsub[4] = w_sub5; valsub[5] = w_sub6; valsub[6] = w_sub7; } field_hidden (w_newsid); printf ("newsid %s
\n",w_newsid.c_str()); printf ("nickname %s submit %s\n
\n",glocal.nickname,glocal.submit); /-
title field_string (w_title,"size=100"); /-
url field_string (w_url,"size=100"); /-
content field_textarea (w_content,10,120,""); /-
static const char *tbsub[]={"Peoples","Technology","Politic","Sports","Arts","Economy","Science"}; for (int i=0; i<7; i++){ printf ("%s",tbsub[i]); char tmp[10]; snprintf (tmp,sizeof(tmp)-1,"sub%d",i+1); field_checkbox (tmp,valsub[i],""); /-     } /-
button_submit ("ok");
bool ret = true; if (w_sub1 == 0 && w_sub2 == 0 && w_sub3 == 0 && w_sub4 == 0 && w_sub5 == 0 && w_sub6 == 0 && w_sub7 == 0){ /- You must assign this news to at least one subject ret = false; } return ret; (glocal.con,w_session.c_str(),w_newsid.c_str()); ::printf ("approve success %d
\n",success); if (success){ vector subjects; if (w_sub1 != 0) subjects.push_back("Peoples"); if (w_sub2 != 0) subjects.push_back("Technology"); if (w_sub3 != 0) subjects.push_back("Politic"); if (w_sub4 != 0) subjects.push_back("Sports"); if (w_sub5 != 0) subjects.push_back("Arts"); if (w_sub6 != 0) subjects.push_back("Economy"); if (w_sub7 != 0) subjects.push_back("Science"); (glocal.con,w_session.c_str(),w_newsid.c_str(),subjects); ::printf ("assignsubject success %d
\n",success);
}
}else{ printf ("Internal error\n"); }
}