/* This file is part of Bolixo. Bolixo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Bolixo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Bolixo. If not, see . */ #include #include #include #include #include #include #include #include #define DEFINE_USERINFO #include "util.h" #include "../bolixo.h" #include "../bolixo.m" #include "webtabs.h" #include #include #include "document.h" #undef INSTRUMENT #include "../instrument.h" #include "../proto/bod_client.protoch" #include "w_var.h" #include "steps.h" #include "../helper.h" void index_doc (DOCUMENT_POINTER &pt, DOC_ID &jump, bool index); void index_doc (DOCUMENT_POINTER &pt, DOC_ID &jump); void index_paste(CONNECT_INFO &con, PARAM_STRING path); void index_setpastemenu (_F_webtable *c, PARAM_STRING path); void index_setcopyitem(CONNECT_INFO &con_sess, PARAM_STRING path, PARAM_STRING modified, PARAM_STRING name); static int index_loadfile(CONNECT_INFO &con, PARAM_STRING filename, string &text) { glocal CONNECT_INFO *con = &con; glocal string *text = &text; glocal int ret = 0; text.clear(); (con,w_session.c_str(),filename,"",false); if (!success){ htmlprintf ("Can't read file: %s\n",msg); glocal.ret = -1; }else{ (*glocal.text) = string((const char*)content.getbuffer(),content.getsize()); glocal bool more = more; while (glocal.more && glocal.ret != -1){ (*glocal.con,w_session.c_str(),handle); if (!success){ glocal.ret = -1; htmlprintf ("Can't read file: %s\n",msg); }else{ (*glocal.text) += string((const char*)content.getbuffer(),content.getsize()); } glocal.more = more; } } return glocal.ret; } static int index_loadfile(CONNECT_INFO &con, PARAM_STRING filename, W_SSTRING &text) { string tmp; int ret = index_loadfile(con,filename,tmp); text = tmp; return ret; } void projects(CONNECT_INFO &con, CONNECT_INFO &con_sess, vector &docpointers) { glocal CONNECT_INFO con = con; glocal CONNECT_INFO con_sess = con_sess; glocal vector *docpointers = &docpointers; static unsigned size[5]={15,35,50,0,0}; (MSG_R(M_PROJECTS),tabs,size); sethelp(); // List projects static WEBID id("tab:projects"); (id,currents[id.c_str()]); sethead (MSG_U(H_PROJECTS,"Owner\tProject")); (glocal.con,w_session.c_str(),"",false); unsigned rownum=0; for (auto &inb:inboxes){ string id = string_f("%s/%s",inb.manager,inb.project); const char *style = "white"; if (glocal.webtabs.selected(id)) glocal.webtable.setcurrent(rownum); string add = string_f("webtab_add=1:%s/%s",inb.manager,inb.project); glocal.webtable.setclickopt (true,"",add); glocal.webtable.setrow (style,rownum,"%s\t%s",inb.manager,inb.project); rownum++; } glocal const char *id = id; glocal string path = string_f ("/projects/%s",id); glocal bool is_public = false; glocal bool is_public_sub = false; const char *pt = strchr(id,'/'); if (pt != NULL){ // is_public is true for the public project // and for sub-directories (direct child) of the public project if (strcmp(pt,"/public")==0){ glocal.is_public = true; }else if (strncmp(pt,"/public/",8)==0 && strchr(pt+8,'/') == NULL){ glocal.is_public = true; glocal.is_public_sub = true; } } { DIV f; f.id(TAB_FORM).print(); (formid); DIV d; d.dispflex().flowcol().print(); const unsigned vspace=tlmpweb_ismobile() ? 10: 3; const unsigned hspace=3; { DIV dd; dd.w(100).flexfixe().vmargins(vspace,0).print(); DIV ddd; ddd.dispflex().flowrow().print(); DIV dddd; dddd.flexfixe().margins(0,hspace).print(); /-#I_NEW_FOLDER New folder dddd.end(); dddd.flexgrow().print(); field_string (w_folder,"style=width:100%"); } { DIV dd; dd.w(100).flexfixe().vmargins(vspace,vspace).print(); url_self (string_f("webtab_add=2:%s%c%ld~%s",glocal.id,WEBTAB_MARK,time(NULL),MSG_U(I_NEWDOC,"New_document")) ,MSG_U(I_CREATENEWDOC,"Create a new document")); } { DIV dd; dd.w(100).flexfixe().print(); DIV ddd; ddd.dispflex().flowrow().print(); DIV dddd; dddd.flexfixe().print(); field_file (w_upload); dddd.end(); dddd.flexgrow().print(); DIV ddddd; ddddd.sfloatright().print(); button_submit(); } return true; glocal bool fail = false; if (strcmp(w_folder.c_str(),"")!=0){ string filepath = string_f("%s/%s",glocal.path.c_str(),w_folder.c_str()); (glocal.con,w_session.c_str(),filepath); if (!success){ glocal.fail = true; htmlprintf (MSG_U(E_CREATEFOLDER,"Can't create folder: %s
\n"),msg); }else{ w_folder.setempty(); }
} if (strcmp(w_upload.c_str(),"")!=0){ const char *tempname = tlmpweb_getfilename(w_upload); string filepath = string_f("%s/%s",glocal.path.c_str(),w_upload.c_str()); (filepath,tempname,glocal.fail); (glocal.con,w_session.c_str(),filepath,content,more); glocal.sendfile.sethandle(handle); glocal.sendfile.setresult(success,msg); (glocal.con,w_session.c_str(),handle,content,more); glocal.sendfile.setresult(success,msg); } keepediting = true; fail = glocal.fail;
} WEBID ID_PROJECT("project",id); (ID_PROJECT,currents[ID_PROJECT.c_str()],offsets[ID_PROJECT.c_str()],5); glocal unsigned dropmenu = dropmenu; if (dropmenu == MENU_HELPPREVIEW){ glocal.webtabs.addtab("2:helppreview",MSG_U(I_HELPPREVIEW,"Preview")); }else if (dropmenu == MENU_UNDELETE){ (glocal.con,w_session.c_str(),glocal.path); if (!success) htmlprintf (MSG_U(E_CANTUNDELETEENTRY,"Can't undelete: %s
\n"),msg);
}else if (dropmenu == MENU_PASTE){ index_paste(glocal.con,glocal.path); }else if (dropmenu == MENU_PREVIEW && glocal.is_public && noline == (unsigned)-1){ glocal.webtabs.addtab(string_f("2:preview-%s",glocal.id),glocal.id); }else{ if (dropmenu == 0) tlmpweb_flushheader(); (glocal.con,w_session.c_str(),glocal.path,"",false,noline,1); if (files.size()!=1){ htmlprintf (MSG_U(E_INTERNAL,"Internal error: %s\n"),msg); }else{ auto &f = files[0]; glocal FILE_TYPE file_type = f.file_type; glocal string fname = string_f("%s/%s",glocal.path.c_str(),f.name); if (glocal.dropmenu == MENU_DELETE){ glocal bool ok = false; if (f.type == ENTRY_FILE){ (glocal.con,w_session.c_str(),glocal.fname); if (!success) htmlprintf (MSG_U(E_CANTDELETEENTRY,"Can't delete: %s
\n"),msg); glocal.ok = success;
}else{ (glocal.con,w_session.c_str(),glocal.fname); if (!success) htmlprintf (MSG_U(E_CANTDELETEDIR,"Can't delete folder: %s
\n"),msg); glocal.ok = success;
} if (glocal.ok) index_setcopyitem(glocal.con_sess,glocal.fname,f.eventdate,f.name); }else if (glocal.dropmenu == MENU_COPY){ index_setcopyitem(glocal.con_sess,glocal.fname,f.eventdate,f.name); }else if (glocal.dropmenu == MENU_RENAME){ glocal const char *oldname = f.name; ("rename"); /- /-
/-#F_OLDNAME Entry current name /- htmlout(glocal.oldname); /-
/-#F_NEWNAME New name /- field_string (w_name,""); /-
return true; glocal bool fail = false; string newname = string_f("%s/%s",glocal.path.c_str(),w_name.c_str()); (glocal.con,w_session.c_str(),glocal.fname,newname.c_str()); if (!success){ glocal.fail = true; htmlprintf (MSG_U(E_RENAME,"Rename failed: %s
\n"),msg); }
fail = glocal.fail;
}else if (glocal.dropmenu == MENU_DOWNLOAD){ tlmpweb_header ("Content-Disposition"," attachment; filename=%s",f.name); util_sendfile (glocal.con,w_session.c_str(),glocal.fname); }else if (glocal.dropmenu == MENU_PREVIEW){ if (glocal.is_public && f.type == ENTRY_DIR){ string tmp = string_f("%s/%s",glocal.id,f.name); glocal.webtabs.addtab(string_f("2:preview-%s",tmp.c_str()),tmp); } }else if (glocal.dropmenu != 0){ if (file_is_text(f.file_type)){ if (f.islarge){ util_sendfile (glocal.con,w_session.c_str(),glocal.fname); }else{ (glocal.con,w_session.c_str(),glocal.fname,""); if (!success){ util_popup (glocal.con,msg,glocal.file_type,info.modified,info.owner,glocal.fname); }else{ util_popup (glocal.con,content,glocal.file_type,info.modified,info.owner,glocal.fname); } } } }else{ util_popup (glocal.con,"",f.file_type,f.modified,f.owner,glocal.fname); } }
}
glocal unsigned status_width=20; // Size of the small icon at the start of each line (new,seen,modified) glocal unsigned rownum = nbskip; // Defines all posible options for dropdown adddrop_opt (MENU_COPY,MSG_U(M_COPY,"Copy")); index_setpastemenu (this,glocal.path); adddrop_opt (MENU_DELETE,MSG_U(M_DELETE,"Delete")); adddrop_opt (MENU_UNDELETE,MSG_U(M_UNDELETE,"Undelete")); adddrop_opt (MENU_RENAME,MSG_U(M_RENAME,"Rename")); adddrop_opt (MENU_DOWNLOAD,MSG_U(M_DOWNLOAD,"Download")); adddrop_opt (MENU_PREVIEW,MSG_U(M_PREVIEWPUB,"Public preview")); adddrop_opt (MENU_HELPPREVIEW,MSG_U(M_HELPPREVIEW,"Preview help")); if (!glocal.is_public) setdrop_hidden (MENU_HELPPREVIEW); if (glocal.is_public){ glocal.webtable.setdrop_default({MENU_PASTE,MENU_PREVIEW,MENU_HELPPREVIEW}); }else{ glocal.webtable.setdrop_default({MENU_PASTE}); } if (tlmpweb_ismobile()){ hide_columns ({2,4}); glocal.status_width=60; }else if (width != 0 && width < 400){ hide_columns ({2,4}); } sethead (MSG_U(H_FOLDER,"\tName\tModified\tOwner\tSize")); (glocal.con,w_session.c_str(),glocal.path,"",false,nbskip,nblines); if (!success) htmlprintf (MSG_U(E_READDIR,"Can't read directory %s: %s
\n"),glocal.path.c_str(),msg); if (!deletes) glocal.webtable.setdrop_disable(MENU_UNDELETE); const char *func = "Popup"; for (auto &f:files){ string path = string_f ("%s/%s",glocal.id,f.name); glocal.webtable.setdrop_hidden (MENU_PREVIEW); if (bolixo_isdir(f.type)){ if (glocal.is_public && !glocal.is_public_sub){ glocal.webtable.setdrop_visible (MENU_PREVIEW); } glocal.webtable.setclickopt (true,"",string_f("webtab_add=1:%s",path.c_str())); }else if (file_is_image(f.file_type)){ glocal.webtable.setclickopt (true,"",string_f("webtab_add=2:%s~%s",path.c_str(),f.name)); }else if (file_is_video(f.file_type)){ glocal.webtable.setclickopt (true,func,"800,800"); }else if (file_is_sound(f.file_type)){ glocal.webtable.setclickopt (true,func,"350,50"); }else if (file_is_text(f.file_type)){ glocal.webtable.setclickopt (true,"",string_f("webtab_add=2:%s~%s",path.c_str(),f.name)); } if (glocal.webtabs.selected(path)) glocal.webtable.setcurrent(glocal.rownum); //static TRANS_NOTLOAD *tbviewed[]={P_MSG_U(I_NEW,"new"),P_MSG_U(I_BLK,"   "),P_MSG_U(I_MOD,"mod")}; static const char *tbviewed[]={"new.png","seen.png","modified.png"}; char sizestr[20]; if (bolixo_isdir(f.type)){ sizestr[0] = '\0'; }else{ snprintf (sizestr,sizeof(sizestr)-1,"%u",f.size); } glocal.webtable.setrow ("white",glocal.rownum,"\t%s%s\t%s\t%s/%s:%s\t%s" ,glocal.status_width ,tbviewed[f.viewed] ,f.name,bolixo_isdir(f.type) ? "/" : "" ,format_date(userinfo.dateformat,f.modified).c_str() ,f.owner,f.listname,f.listmode,sizestr); glocal.rownum++; }
glocal const char *formid = formid; glocal const char *filename = id; glocal string path = string_f("/projects/%s",glocal.filename); glocal bool newdocument = false; FILEINFO info; if (util_entrytype(glocal.con,glocal.path,info)==ENTRY_DIR){ glocal.newdocument = true; info.file_type = FILE_TEXT; } if (strcmp(id,"help")==0){ DIV d("webtable"); d.print(); index_doc((*glocal.docpointers)[SECTION_PROJECT],section_project); }else if (strcmp(id,"helppreview")==0){ DIV d("webtable"); d.print(); index_doc((*glocal.docpointers)[SECTION_PREVIEW],section_preview); }else if (strcmp(id,"helpmain")==0){ DIV d("webtable"); d.print(); index_doc((*glocal.docpointers)[SECTION_NONE],section_none); }else if (strncmp(id,"preview-",8)==0){ glocal const char *base = id+8; glocal string groupowner; const char *pt = strchr(glocal.base,'/'); if (pt != NULL) glocal.groupowner = string(glocal.base,pt-glocal.base);; DIV dd; dd.id(TAB_FORM).bg("#F1F1F1").paddings(5,5).print(); htmlprintf (MSG_U(I_PREVIEW,"Preview of the folder %s"),glocal.base); /-
dd.end(); // DIV d("wwebtable"); d.print(); (); glocal vector *msgs = &msgs; glocal int ret = -1; (glocal.con,w_session.c_str(),"","public",glocal.groupowner,offset,nb,""); if (success){ glocal.ret = 0; glocal.msgs->clear(); for (auto &m:messages) glocal.msgs->push_back(m); } return glocal.ret; glocal int ret = -1; glocal vector *files = &files; string fname; if (strcmp(path.ptr,"/")==0){ fname = string_f("/projects/%s",glocal.base); }else{ fname = string_f("/projects/%s%s",glocal.base,path.ptr); } (glocal.con,w_session.c_str(),fname,"",false,offset,nb); if (success){ glocal.ret = 0; glocal.files->clear(); for (auto &f:files) glocal.files->push_back(f); } return glocal.ret; glocal int ret = -1; glocal BOB_TYPE *content = &content; string fname = string_f("/projects/%s/%s",glocal.base,path.ptr); (glocal.con,w_session.c_str(),fname,"",true); if (success){ glocal.ret = 0; *glocal.content = content; } return glocal.ret; string ret; string tmp = util_flipspaces(modified.ptr); if (is_any_of(name.ptr,"/photo.jpg","/mini-photo.jpg")){ // Those tow are located in the public folder directly ret = string_f("%s?webstep=%d&image=/projects/%s/public%s&mod=%s" ,tlmpweb_curpage(),step_image,glocal.groupowner.c_str(),name.ptr,tmp.c_str()); }else if (is_image){ const char *slash = name.ptr[0] == '/' ? "" : "/"; ret = string_f("%s?webstep=%d&image=/projects/%s%s%s&mod=%s" ,tlmpweb_curpage(),step_image,glocal.base,slash,name.ptr,tmp.c_str()); }else{ string hidden; form_gethidden(hidden); ret = string_f("%s?file=%s&%s",tlmpweb_curpage(),name.ptr,hidden.c_str()); } return ret; string ret; const char *pt = strchr(glocal.base,'/'); if (pt != NULL){ string user (glocal.base,pt-glocal.base); string tmp = util_flipspaces(modified.ptr); ret = string_f("%s?webstep=%d&image=/msgs/%s/short-inbox/public/%s&mod=%s" ,tlmpweb_curpage(),step_image,user.c_str(),name.ptr,tmp.c_str()); } return ret; glocal string website; glocal string interest; (glocal.con,w_session.c_str(),""); if (success && info.publish){ glocal.website = info.website; glocal.interest = info.interest; } public_display (*this,glocal.con,userinfo.name,true,glocal.website,glocal.interest); string fname = string_f("/projects/%s/%s",glocal.base,name.ptr); tlmp_error ("sendfile %s\n",fname.c_str()); util_sendfile(glocal.con,w_session.c_str(),fname); }else if (file_is_image(info.file_type)){ DIV d("webtable"); d.print(); DIV dd; dd.id(TAB_FORM).bg("#F1F1F1").paddings(5,5).print(); htmlprintf (MSG_R(I_DOCNAME),glocal.filename); /-
dd.end(); htmlout (util_img(step_image,"max-width:100%; max-height=100%;",glocal.path,info.modified)); }else if (info.file_type == FILE_TEXT){ (formid); if (!glocal.newdocument){ index_loadfile(glocal.con,glocal.path,w_content); } { DIV f; f.id(TAB_FORM).w(100).print(); const unsigned vspace=3; DIV d; d.dispflex().flowrow().print(); DIV dd; dd.flexfixe().vmargins(vspace,0).print(); if (glocal.newdocument){ /-#I_NEWDOCNAME Name  field_string (w_filename,"size=25"); }else{ const char *filename = glocal.filename; if (tlmpweb_ismobile()){ const char *pt = strrchr(filename,'/'); if (pt != NULL) filename = pt+1; } htmlprintf (MSG_U(I_DOCNAME,"Document name: %s"),filename); } dd.end(); dd.flexgrow().print(); DIV ddd; ddd.sfloatright().print(); button_submit(MSG_U(B_SAVE,"Save")); } WEBID id ("prjtext",glocal.formid); field_textarea(w_content,id,-100,"style=\"border:none\""); bool ret = true; if (glocal.newdocument){ if (strcmp(w_filename.c_str(),"")==0){ /- You must provide a file name ret = false; }else if (util_entrytype(glocal.con,string_f("%s/%s",glocal.path.c_str(),w_filename.c_str()))!=ENTRY_NONE){ /- Document already exist ret = false; } } return ret; (glocal.path,w_content,fail); if (glocal.newdocument){ glocal.path = string_f("%s/%s",glocal.path.c_str(),w_filename.c_str()); (glocal.con,w_session.c_str(),glocal.path,content,more); glocal.sendfile_var.setresult(success,msg); glocal.sendfile_var.sethandle(handle); }else{ (glocal.con,w_session.c_str(),filepath,content,more); glocal.sendfile_var.setresult(success,msg); glocal.sendfile_var.sethandle(handle); } (glocal.con,w_session.c_str(),handle,content,more); glocal.sendfile_var.setresult(success,msg); if (!fail){ if (glocal.newdocument){ WEBID oldid ("prjtext",glocal.formid); string newtabid = string_f("%s/%s",glocal.filename,w_filename.c_str()); glocal.webtabs.setid (newtabid); glocal.webtabs.settitle (w_filename.c_str()); glocal.webtabs.redotab(); resetstate(); // We have to mark this document as viewed (we just created it) util_markview (glocal.con,glocal.path); WEBID newid ("prjtext",newtabid); webtable_rename_scroll(oldid.c_str(),newid.c_str()); }else{ keepediting = true; } } }
/- }